Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compare two datetimes - without hour and second

Tags:

c#

As the title states, what's the best way to compare to DateTime's without hours and seconds?

I don't want to convert my dates to string, and a solution like

DateTime.Now.Year == last.Year && DateTime.Now.Month == last.Month && DateTime.Now.Day == last.Day

is pretty damn ugly.

Edit: Oh my god, how silly I feel. Of course you can use the Date property.

"Another question": What is the best way to compare DateTime's with Year, Month, Day, Hour, Minute, but not seconds?

Thanks

like image 724
alexn Avatar asked Aug 17 '09 07:08

alexn


2 Answers

Is this: what you're looking for?

DateTime.Now.Date
like image 125
Noon Silk Avatar answered Sep 30 '22 23:09

Noon Silk


Take a look at the Date property, then you can compare dt1.Date with dt2.Date.

like image 30
Levi Avatar answered Sep 30 '22 22:09

Levi