Grid with Date Only field - value off by one day

4 posts, 0 answers
  1. Brian
    Brian avatar
    10 posts
    Member since:
    Jun 2011

    Posted 07 Dec 2013 Link to this post

    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
  2. Alexander Popov
    Admin
    Alexander Popov avatar
    1416 posts

    Posted 10 Dec 2013 Link to this post

    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!
  3. Kendo UI is VS 2017 Ready
  4. Alexandre
    Alexandre avatar
    20 posts
    Member since:
    Apr 2014

    Posted 12 Aug 2014 Link to this post

    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.
  5. Alexander Popov
    Admin
    Alexander Popov avatar
    1416 posts

    Posted 14 Aug 2014 Link to this post

    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!
     
Back to Top
Kendo UI is VS 2017 Ready