I have run across a number of questions in the asp.net forum that are easily solved with this little-known but very useful property of DateTime objects - namely the Date property. I figured it would be worth a quick post because where it is handy it is very handy...
All Date does is simply zero out the hours, leaving you with the Date set to 12 am (or 00:00:00). This makes it simple, for example to see if two different DateTime objects occur on the say day, regardless of the hour without having to do any fancy multi-property comparisons:
myFirstDateTime.Date.CompareTo(mySecondDateTime.Date)
You could also do the same with using the ToShortDateTimeString and using a string comparison, but besides the conversion (and the issues re strings objects in general) why not use something native to DateTime?
dasBlog theme by Mads Kristensen
Disclaimer The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.