Harugawa Harugawa - 2 months ago 9
C# Question

Comparing datetimes in eval to hours

I've got a datetime and I want to check if there is 24 hours difference between those two. I just don't know how to do that.
So far I've got this:

<%# (DateTime.Now - Convert.ToDateTime(Eval("new_date"))) < 24 ? "Today" : Eval("new_date") %>


It does not work tho :<
@Edit
And this is how datetime in my database looks like for example:

2016-09-18 12:26:14

Answer

The difference between 2 DateTimes is a TimeSpan, which has a TotalDays property you could compare to 1..

Comments