• Login

Snippets

28

/// <summary>
 /// Returns the first day of the next month.
/// </summary>
/// <example>
/// i.e. If start date is 9/27/2009 it will return 10/1/2009.
/// i.e. If date is 02/28/2001 it will return 03/01/2009
/// i.e. Id date is 2/1/2009 it will return 2/01/2009
/// </example>
/// <remarks>
/// This method will not advace a month if the date is already on the first day of the month.
/// </remarks>
/// <param name="startDate"></param>
/// <returns>The first day of the next month from given start date.</returns>

public static DateTime GetFirstDayOfNextMonth(DateTime startDate)

{

if (startDate.Month == 12) // its end of year , we need to add another year to new date:

{

startDate = new DateTime((startDate.Year + 1), 1, 1);

}

else

{

startDate = new DateTime(startDate.Year, (startDate.Month + 1), 1);

}

return startDate;

}

 

 

Posted in: C Sharp - C#

Post Rating

Comments

There are currently no comments, be the first to post one!

Post Comment

Name (required)

Email (required)

Website