Here's a some functions I wrote. There may be faster ways to do this:
/// <summary>
/// Determines the first date of the month/year specified
/// </summary>
/// <param name="date">Any DateTime value that is in the month
desired</param>
/// <returns>A DateTime value of the first date of the month
specified</returns>
static public DateTime GetFirstDateOfMonth(DateTime date)
{
return (DateTime.Parse(date.Month.ToString() + "/01/" +
date.Year.ToString()));
}
/// <summary>
/// Determines the first date of the month/year specified
/// </summary>
/// <param name="Month">Number of month (1 - 12) desired</param>
/// <param name="Year">Year (YYYY) of month desired</param>
/// <returns>A DateTime value of the first date of the month
specified</returns>
static public DateTime GetFirstDateOfMonth(int month, int year)
{
return (DateTime.Parse(month.ToString() + "/01/" + year.ToString()));
}
/// <summary>
/// Determines the last date of the month/year specified
/// </summary>
/// <param name="date">Any DateTime value that is in the month
desired</param>
/// <returns>A DateTime value of the last date of the month
specified</returns>
static public DateTime GetLastDateOfMonth(DateTime date)
{
return (DateTime.Parse(date.Month.ToString() + "/" +
DateTime.DaysInMonth(date.Year, date.Month).ToString() + "/" +
date.Year.ToString()));
}
/// <summary>
/// Determines the last date of the month/year specified
/// </summary>
/// <param name="Month">Number of month (1 - 12) desired</param>
/// <param name="Year">Year (YYYY) of month desired</param>
/// <returns>A DateTime value of the last date of the month
specified</returns>
static public DateTime GetLastDateOfMonth(int month, int year)
{
return (DateTime.Parse(month.ToString() + "/" + DateTime.DaysInMonth(year,
month).ToString() + "/" + year.ToString()));
}
Ante Perkovic said:
"Jay B. Harlow [MVP - Outlook]" <
[email protected]> wrote in
message news: said:
Dim birthday As New DateTime(2003, 6, 28)
...
Dim birthday As DateTime = #6/28/2003#
...
Hope this helps
Jay
Yes, thanks.
But, I still don't know how to easily set date to the first day of
this month (if I don't know which is the current month).
I need something like this:
Dim begginingOfThisMonth As Date = DateTime.Today.setDay(1)
Is there an easy way to do this?
How to declare datetime object and set it to my birthday, first or
last day of this month or any other date.