views:

92

answers:

1
<%= Html.ActionLink(Html.Encode("user3"),
  "Filter", new { controller = "Search",
   userName = "user3", 
   dateFrom = DateTime.Now.AddDays(-2).ToString(), 
   dateTo = DateTime.Now.ToString() })%>

It's evaluated to this link:

http://localhost:60357/Search/Filter?userName=user3&amp;dateFrom=08.02.2010%2023%3A21%3A33&amp;dateTo=10.02.2010%2023%3A21%3A33

I have to notice that current Globalization settings in Windows are set up to european date format. So 08.02.2010 = 08 Feb 2010.

But in the action method

public ActionResult Filter(String userName, DateTime dateFrom, DateTime dateTo)

dateFrom has the value 02.08.2010 = 02 Aug 2010

It's incorrect. Is it framework bug? So what is the best way to solve this issue? I don't want to write some monkeypatch if possible.

+5  A: 

Don't use DateTime.Now.ToString(). Use DateTime.Now.ToString("s") (ISO 8601 format -- yyyy-MM-ddTHH:mm:ss) There is only one possible way to interpret that, so it's never wrong -- at least, until you start dealing with time zones! (Consider "u" format for that.)

Craig Stuntz
You are definitely right! Thank you!
Overdose