posted 11/22/2011 by Raghav Khunger
Yeterday I had a requirement where I needed to find the end of day in datetime. I decided to make extension on datetime to achieve it. Below is the sample code:DateTimeExtension.cs:
#region Using Directives using System; #endregion namespace Sample.Console { public static class DateTimeExtension { public static DateTime GetEndOfDay(this DateTime datetime) { return datetime.AddDays(1).AddTicks(-1); } }//end class }//end namespace
using System; using System.Text.RegularExpressions; namespace Sample.Console { internal class Program { private static void Main(string[] args) { DateTime t = DateTime.Today.GetEndOfDay(); System.Console.WriteLine(t); System.Console.ReadLine(); } } }
Output:
What kind of email newsletter would you prefer to receive from CodeAsp.Net?18