This is a migrated thread and some comments may be shown as answers.

Datasource date format incompatibile with ASP.NET MVC date format

3 Answers 186 Views
Globalization
This is a migrated thread and some comments may be shown as answers.
martonx
Top achievements
Rank 1
martonx asked on 01 Aug 2012, 03:38 PM
Hi,

This is a strange problem. I have a grid with dates from ASP.NET MVC. In the grid the dates are look OK.
I'm using "hu-HU" globalization.
When I update, or create a row, the sended date is this format: Wed Aug 1 17:32:58 UTC+0200 2012
This looks like in httpencoding in GET: projects%5B0%5D.start=Wed+Aug+01+2012+00%3A00%3A00+GMT%2B0200+(K%C3%B6z%C3%A9p-eur%C3%B3pai+ny%C3%A1ri+id%C5%91) 
And here it is my MVC controller action:
public JsonResult CreateProject(IEnumerable<ProjectViewModel> projects){...}

When I check projects I see that date's parsed failed so I see my Datetimes in my incoming object: {0001.01.01. 0:00:00}

Please advice, what should I do for good date communication protocol?

Thank you very much!

3 Answers, 1 is accepted

Sort by
0
Sig
Top achievements
Rank 1
answered on 10 Sep 2012, 02:58 AM
I'm having a very similar issue.

When I post form data back from a Kendo control (in this case a date-picker), it's posts the date as follows:
Tue Sep 04 2012 00:00:00 GMT-0700 (Pacific Daylight Time)

The issue I have is that I want it to post in a different format.... the above format is not readily parse-able for asp.net mvc when model-binding.  Is there a good workaround to grab the date and modify it prior to posting the data on a form-submit?

Thanks!
0
Sig
Top achievements
Rank 1
answered on 10 Sep 2012, 03:15 AM
Ok, I think I found the issue I was having...

When posting data, it looks like IE vs. Firefox vs. Chrome all behave slightly differently. 
Below are the possibilities of dates in various browsers:
IE 10: "Tue Sep 4 00:00:00 PDT 2012"
Firefox 15:01: "Tue Sep 04 2012 00:00:00 GMT-0700 (Pacific Daylight Time)"
Chrome 21.0.1180.89: "Tue Sep 04 2012 00:00:00 GMT-0700 (Pacific Daylight Time)"

That would explain why I can parse dates in IE, but not in Firefox and chrome (asp.net mvc doesn't understand dates with the appeneded "Pacific Daylight Time". 

My option is to trim a string to not contain anything from the first location of a parentheses on, and that seems to solve the issue, but there has to be a way to tell Kendo what format to pass dates in, right?

Anyone have any thoughts on this?
0
Sig
Top achievements
Rank 1
answered on 10 Sep 2012, 03:37 AM
Good stack overflow article for MartinX and anyone else reading this thread:
http://stackoverflow.com/questions/10197437/how-to-convert-string-to-date-time
Tags
Globalization
Asked by
martonx
Top achievements
Rank 1
Answers by
Sig
Top achievements
Rank 1
Share this question
or