FirstDayOfMonth / LastDayOfMonth
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"); } }Example:
DateTime dateToday = DateTime.Now; Console.WriteLine("First Day: {0}", dateToday.FirstDayOfMonth()); Console.WriteLine("Last Day: {0}", dateToday.LastDayOfMonth());
Description
Simple way to Get the first and last day of the specified date.
Details
- Author: Earljon Hidalgo
- Submitted on: 30-3-2008 08:57:51
- Language: C#
- Type: System.String
- Views: 4521
Double click on the code to select all.