C# Get 1 Day of The Month And Last Day of The Month

Problem : Getting first and last day of the month.

Solution :

 // Get Last Day Of The Month
public static DateTime GetLastDayOfMonth(int year, int month)
{
    return new DateTime(year, month, DateTime.DaysInMonth(year, month));
}

// Get 1 Day Of The Month
public static DateTime GetFirstDayOfMonth(int year, int month)
{
    return new DateTime(year, month, 1);
}

0 comments: