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

Grid with Date Only field - value off by one day

3 Answers 725 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Brian
Top achievements
Rank 1
Brian asked on 07 Dec 2013, 05:53 PM
I suspect this question has already been asked and answered elsewhere in the forum, and, it might be more about JSON than the grid.

I am using the MVC wrappers to build a grid.  The grid has two “date only” (no time) fields.  I am using the Kendo DatePicker widget, but I suspect this is more appropriately a grid question.  The grid is using .Ajax() for CRUD operations (which uses JsonResult). 
     Ex:  return Json(new[] { m }.ToDataSourceResult(request, ModelState));

When the server and the user are in two different time zones, I get a displayed date that is off by one day.  I assume this is because the time is midnight, and the time zone adjustment is turning midnight on the 15th into 11pm on the 14th  (for example).

I tried sending UTC DateTime, but that did not work:
     m.StartDate = m.StartDate.ToUniversalTime();

Is there a standard solution for this?  I have seen a lot of writeups related to this issue, but most of them don’t directly address Kendo Grid using MVC wrappers and Ajax calls.

Thanks,
R

3 Answers, 1 is accepted

Sort by
0
Alexander Popov
Telerik team
answered on 10 Dec 2013, 03:33 PM
Hello Rich,

I would recommend you to check our Code Library project demonstrating how to use UTC time both server and client-side.

Regards,
Alexander Popov
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Alexandre
Top achievements
Rank 1
answered on 12 Aug 2014, 06:46 PM
Hi,

I had a similar problem: although the attribute [DataType(DataType.Date)] is set on the property, the date display on the grid is off by one day. I have apply successfully the UTC workaround as describe in the example. However it is my opinion that grid should not modify the data even when the client and the server are using different time zones unless the programmer request it in option and even then not when the data type is date.
Michael
Top achievements
Rank 1
commented on 02 Mar 2022, 07:42 PM

I wholeheartedly agree. Data conversion should remain in the purview of the developer. No assumption should be made by the control being used. This is a real nightmare to manage.
0
Alexander Popov
Telerik team
answered on 14 Aug 2014, 11:12 AM
Hi Alexandre,

The Grid itself is not modifying the dates in any way. Date objects in JavaScript however, are always created with a timezone offset and this is where the difference comes from.

Regards,
Alexander Popov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
Grid
Asked by
Brian
Top achievements
Rank 1
Answers by
Alexander Popov
Telerik team
Alexandre
Top achievements
Rank 1
Share this question
or