ExtensionMethod.NET Home of 840 C#, Visual Basic, F# and Javascript extension methods

FirstDayOfMonth / LastDayOfMonth

Simple way to Get the first and last day of the specified date.


public static class DateExtensions
	public static string FirstDayOfMonth(this DateTime date)
		return new DateTime(date.Year, date.Month, 1).ToString("MM/dd/yyyy");

	public static string LastDayOfMonth(this DateTime date)
		return new DateTime(DateTime.Now.Year, DateTime.Now.Month + 1, 1).AddDays(-1).ToString("MM/dd/yyyy");


DateTime dateToday = DateTime.Now;

Console.WriteLine("First Day: {0}", dateToday.FirstDayOfMonth());
Console.WriteLine("Last Day: {0}", dateToday.LastDayOfMonth());

Author: Earljon Hidalgo

Submitted on: 30 mrt 2008

Language: C#

Type: System.String

Views: 5931