How do I pass a date via the URL?
Here is what I am trying to do, as as you'll see the date uses forward slashes which are invalid in the URL
http://localhost/Controller/Action/id=0d5375aa-6d43-42f1-91f0-ea73d9beb361&date=02/12/2009
The ISO 8601 standard is yyyy-MM-dd, which is unambiguous and does not contain any invalid URL characters, and works fine in DateTime.Parse/TryParse.
Another option is to use whatever format you want and simply encode the URL using HttpServerUtility.UrlEncode/UrlDecode.
You could pass a date in the query string using a specific format, say yyyymmdd and then parse it correctly in your Controller.
&date=02/12/2009
change to
&date=20091202 (yyyymmdd)
You could either create a wrapper around the DateTime object that was instantiated using this new format or just parse it yourself in the Controller.
public MyWrapperDate(int date)
{
int year = date / 10000;
int month = ((date - (10000 * year)) / 100);
int day = (date - (10000 * year) - (100 * month));
this.DateTimeObject = new DateTime(year, month, day);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With