I have a simple comparison in my view to see if an event is in the past:
<% if (model.EventDate < DateTime.Now)
{ %>
<td style="color: red;">
<% }
else
{ %>
<td>
<% } %>
This works fine on my dev machine, running via Cassini, but on the server it seems to be interpreting 01/12/2010 as Dec. 1, not Jan 12.
How should I be doing this comparison to make sure that it works the same regardless of the runtime environment?
Update: The EventDate is a DateTime, and is coming from a database, which has the correct date: select MONTH(EventDate) returns 1, select DAY(EventDate) returns 12.
Best Solution
Comparing two
DateTime
instances in .NET always works. The problem lies when you setmodel.EventDate
, maybe you are parsing it from a string.