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 开发者_JAVA技巧a database, which has the correct date: select MONTH(EventDate) returns 1, select DAY(EventDate) returns 12.
Comparing two DateTime
instances in .NET always works. The problem lies when you set model.EventDate
, maybe you are parsing it from a string.
The server is running under a different culture than your dev box. This is one of the reasons why people should save dates as UTC.
As a work around you could try adding the following into your web.config (it's a child of <system.web>):
<globalization culture="en-US" />
HTHs,
Charles
精彩评论