posted 7/5/2011 by Raghav Khunger
Today I was working with a datetime field where I needed midnight datetime of that date. The solution was to subtract the time of day from the date. Here is the code for it:
private static void Main(string[] args) { DateTime myDateTime = DateTime.Now; DateTime midnight = myDateTime.Subtract(myDateTime.TimeOfDay); Console.WriteLine("Original DateTime: " + myDateTime); Console.WriteLine("Midnight DateTime: " + midnight); Console.ReadLine(); }
What kind of email newsletter would you prefer to receive from CodeAsp.Net?18