Skip to content

Infragistics Community Forum / Web / Ignite UI for jQuery / Date is one day behind although EnableUtcDates= true

Date is one day behind although EnableUtcDates= true

New Discussion
zep lin
zep lin asked on Nov 17, 2014 2:16 PM

Hi,

My dates in the grid are being displayed one day behind even though I have set the EnableUtcDates(true).

I have enabled UTCDates in my grid model through the MVC GridModel() method like this :

GridModel GetGridModel(selectedRow) {

GridModel gridModel = new GridModel();
gridModel.ID = “MyGrid”;
gridModel.AutoGenerateColumns = false;
gridModel.PrimaryKey = selectedRow.PrimaryKey;
gridModel.Width = “100%”;
gridModel.Height = “400px”;
gridModel.EnableUTCDates = true;

    …. ….// other settings

    ….. ……

             return gridModel;

}

1) The date I get from server is 7/1/2012 00:00:00.000 & the grid displays 6/30/2012  (Here the month & day both are decremented because of 1st date)

2) The date I get from server is 11/11/2014 00:00:00.000 & the grid displays 11/10/2014 (Here only the day is decremented)

—————

This issue is also discussed here but the answer suggests to enable UTCDates feature of the grid.

http://www.infragistics.com/community/forums/t/80982.aspx

I have enabled UtcDates, I am still facing the issue. What am I doing wrong?

Thanks.

Sign In to post a reply

Replies

  • 0
    [Infragistics] Michael H.
    [Infragistics] Michael H. answered on Oct 27, 2014 10:12 PM

    Hi zep lin,

     

    Thank you for posting in our forums!

    I will need a little more time to investigate why the dates continue to be offset while EnableUTCDates is true.  First, please answer the following questions for me so I may better assist you with this:

    1.) Which version and build of IgniteUI you are using. e.g. 14.1.20141.2249

    2.) How is the Date being passed into the grid?  Are you sending it directly as JSON from the server?

    Looking forward to hearing from you.

    • 0
      zep lin
      zep lin answered on Oct 28, 2014 6:25 AM

      Thanks Michael for the response.

      1) I am using 2013.2 version of infragistics. Version 4.13.2.2157

      2) This method converts my collection to json and then passes it on to the grid:

      public ActionResult ConvertToJson<T>(ResponseWrapper<T> result)
              {
                  ResponsePacket<T> dataViewModel = new ResponsePacket<T>();
                  JsonResult jsonResult = new JsonResult();

                  var pageSize = HttpUtility.ParseQueryString(Request.Url.Query).Get("pageSize");
                  var pageIndex = HttpUtility.ParseQueryString(Request.Url.Query).Get("page");

                  if (pageSize == null || pageIndex == null)
                  {
                      dataViewModel.Records = result.Content;
                      dataViewModel.RecordCountKey = result.recordCountKey;
                      jsonResult.Data = dataViewModel.Records;
                      jsonResult.JsonRequestBehavior = JsonRequestBehavior.AllowGet;
                  }
                  else
                  {
                      dataViewModel.Records = result.Content.AsQueryable();
                      dataViewModel.RecordCountKey = result.recordCountKey;
                      jsonResult.Data = dataViewModel;
                      jsonResult.JsonRequestBehavior = JsonRequestBehavior.AllowGet;
                  }

                  return jsonResult;

              }

      The grid model is set up on my controller & the gridModel is generic in a way that it is for all the entities & the columns are set up dynamically like this :

       gridModel.Columns.Add(new GridColumn()
                          {

                             //record is my result set which contains the MetaData of the database table
                              HeaderText = record.DisplayName,   
                              Key = record.ColumnName,
                              DataType = record.DataType
                          });

      • 0
        [Infragistics] Michael H.
        [Infragistics] Michael H. answered on Oct 28, 2014 9:35 PM

        Hello zep lin,

         

        Thank you for the information.  I will need a little more time to look into this issue.  In an effort to get you a solution more quickly, I have asked my colleagues in another office to assist with this.

        If you have any further questions or concerns with this, please let us know.

      • 0
        [Infragistics]Denis Georgiev
        [Infragistics]Denis Georgiev answered on Oct 29, 2014 1:04 PM

        Hello Zep,

        Thank you for your patience!

        I have reviewed the provided information so far and I have tried to reproduce the issue by the given code, but I didn't had any access. 

        Could you please provide an isolated working code sample so I can test it and investigate the source of the issue?

        Thank you in advance!

      • 0
        zep lin
        zep lin answered on Oct 31, 2014 10:03 AM

        Hello Denis,

         I think it has something to do with the timezone but I am not sure how to set the correct time zone.

        This stackoverflow post is exactly what I am experiencing & the answers there suggest of using the correct time zone. This is the link , please have a look here. How can I set the correct time zone. My local time zone is Gmt +5.

        http://stackoverflow.com/questions/7556591/javascript-date-object-always-one-day-off

        The first answer on StackOverflow is this :

        Notice that Eastern Daylight Time is -4 hours and that the hours on the date you're getting back are 20.

        20h + 4h = 24h

        which is midnight of 2011-09-24.

        You're getting the right date, you just never specified the correct time zone.

        If you need to access the date values, you can use getUTCDate() or any of the other getUTC*() functions:

        var d, days; d = new Date('2011-09-24'); days = ['Sun', 'Mon', 'Tues', 'Wed', 'Thurs', 'Fri', 'Sat']; console.log(days[d.getUTCDay()]);



        Do I have to pass all of my dates through this routine & add +4 hours to them or is there another way.
        Thanks.

      • 0
        [Infragistics]Denis Georgiev
        [Infragistics]Denis Georgiev answered on Oct 31, 2014 10:41 AM

        Hello Zep,

        You can use a formatter function to workaround this.

        Please review the attached sample.

      • 0
        zep lin
        zep lin answered on Oct 31, 2014 11:42 AM

        Thanks I will implement it  in 3-4 days and let you know how it goes. Thanks for the help.

      • 0
        [Infragistics]Denis Georgiev
        [Infragistics]Denis Georgiev answered on Oct 31, 2014 11:47 AM

        I will be awaiting your feedback.

      • 0
        [Infragistics]Denis Georgiev
        [Infragistics]Denis Georgiev answered on Nov 5, 2014 3:59 PM

        Hello,

        I'm just following up to see if you need any further assistance with this issue. If so please let me know.

      • 0
        zep lin
        zep lin answered on Nov 10, 2014 6:50 AM

        Hello Denis,

        I implemented your solution, Its not working for me. The following was the result I was getting BEFORE implementing your soultion:

        The date on the server is : 2014-11-12 00:00:00.000

        The date in the grid is : 11/11/2014 _7:00 PM

        (12th date becomes 11th)

        After I implemented your sample project I get a completely wrong date, I cant figure out the implementation details of your formatToServerTimeZone(date) function, is it specific to Pennsylvania? Are Daylight Savings setting different for every region ? Then this would be a problem. I dont want to hardcode the daylight saving settings. The following line does not make sense to me and if I have to modify it according to my region then this would become region specific, I dont think there is Daylight Saving in my country right now so what should be the setting?

        Also one more thing.

        I have a form (Master) also above the grid (Detail) . The same date 2014-11-12 00:00:00.000 from server is loaded in the form's datePicker and the date is displayed correctly like this : 11/12/2014

        There is an event bound to this datePicker, on its selection changed event, the date of this (master's) datePicker is used to set the date in my Grid (detail). And the date 11/12/2014 becomes 11/11/2014 _7:00 PM . And if I commit the data the server's date also becomes 11/11/2014 00:00:00.000 BUT if I use the datePicker inside the grid (detail) and select 11/12/2014 then the correct date is displayed in the grid as well as on committing the row the server's date becomes 2014-11-12 14:00:00.000 and is displayed correctly next time in the grid.

        From what I understand is that if I change the grid's date column through my master's datePicker, the date becomes one day behind, If I set the date through the grid's columns datePicker the date displays alright and the server also stores it correctly.


        var date = $("#voucherPartyRefDate").igEditor("value");    // get date from master's datePicker

        $("#voucherDetailGrid").igGridUpdating("updateRow", detailHeaderPk, {  //set date of detail(grid's) datePicker

        vchr_dtl_ref_dt: date

        }

        ———————————–

        If this is messing up the date than what should be done ? Is there another way to set the date of grid date column based on the date selected from master's igDatePicker?

        Thanks.
                    

      • 0
        [Infragistics]Denis Georgiev
        [Infragistics]Denis Georgiev answered on Nov 10, 2014 7:14 AM

        Hello Zep,

        Provide isolated sample project replicating your issue so I can be able to investigate this behavior.

      • 0
        Maya Kirova
        Maya Kirova answered on Nov 10, 2014 5:12 PM

        Hello zep lin,

         The EnableUTCDates option only formats the date it received from the server to UTC. 

        Basically the date values go through a formatter method that depending on the EnableUTCDates option either builds the value with the standard date object methods in local time (getFullYear(), getMonth(), getDate(),getHours() etc.) or via the methods UTC equivalents in UTC time ( getUTCFullYear(), getUTCMonth(), getUTCDate(), getUTCHours() etc.). The formatted value is what you’ll see in the cells of the grid once it's rendered.

        This is also true for the igDatePicker and igDateEditor.

         

        In your case most probably the dates you send from the backend are not in UTC (DateTime.Kind is not UTC but Local) which means that they have their own offset from UTC which will not be taken into consideration in cases where the Json data is manually retuned from an action result.

         

        If you’re using also any of the editor controls (igDatePicker and igDateEditor) you should also set EnableUTCDates to true for them as well in order to have consistent dates from the same time zone.

         

        Best Regards,

        Maya Kirova

        Product Developer

        Infragistics, Inc.

        http://www.infragistics.com/support

         

         

      • 0
        [Infragistics]Denis Georgiev
        [Infragistics]Denis Georgiev answered on Nov 14, 2014 7:45 AM

        Hello Zep,

        Have you been able to resolve the issue? If not so I am still awaiting your sample project.

      • 0
        Jimmy Page
        Jimmy Page answered on Nov 17, 2014 2:16 PM

        If you’re using also any of the editor controls (igDatePicker and igDateEditor) you should also set EnableUTCDates to true for them as well in order to have consistent dates from the same time zone.


        I was facing the same problem. The issue was this: I had enabled UTCDates in the grid but I hadnt set UTCDates in my igEditor therfore the value I set from igEditor was being set as one day behind in the igGrid. Thanks for the question & your help. Appreciate it.

  • You must be logged in to reply to this topic.
Discussion created by
Favorites
Replies
Created On
Last Post
Discussion created by
zep lin
Favorites
0
Replies
14
Created On
Nov 17, 2014
Last Post
11 years, 3 months ago

Suggested Discussions

Tags

Created by

Created on

Nov 17, 2014 2:16 PM

Last activity on

Feb 25, 2026 9:59 AM