I need to create a midnight DateTime
I've just done this:
DateTime endTime = DateTime.Now;
endTime.Subtract(endTime.TimeOfDay);
Haven't test it yet, I'm assuming it works but is there a better/cleaner way?
I need to create a midnight DateTime
I've just done this:
DateTime endTime = DateTime.Now;
endTime.Subtract(endTime.TimeOfDay);
Haven't test it yet, I'm assuming it works but is there a better/cleaner way?
DateTime endTime = DateTime.Now.Date;
Now endTime.TimeOfDay.ToString()
returns "00:00:00"
Thanks for this post, it helped me to put this together where I need midnight tonight to be the cut-off point for a database query:
public string MidnightTonight()
{
DateTime today = DateTime.Now.Date;
return today.ToString("yyyy'/'MM'/'dd") + " 23:59:59";
}
I tried AddDays(1) but if I run the query at 3pm today, that would give me 3pm tomorrow rather than midnight tonight, wouldn't it?