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

FirstDayOfMonth

Return the first day of the mounth for a given date

Source

public static DateTime FirstDayOfMonth(this DateTime value)
{
   return new DateTime(value.Year, value.Month, 1);
}

Example

var date = new DateTime(2023, 01, 30);

int firstDay = date.FirstDayOfMonth();

Author: Fernando Sarturi Prass

Submitted on: 30 jan. 2023

Language: csharp

Type: System.DateTime

Views: 2002