views:

38

answers:

3

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.

A: 

Comparing two DateTime instances in .NET always works. The problem lies when you set model.EventDate, maybe you are parsing it from a string.

Darin Dimitrov
A: 

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.

Will
A: 

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

Charlino