I have an igGrid where one column is a date. For some reason, the date displayed is always one day behind the date's value.
The column definition is:
{ headerText: "Settlement Date", key: "settlement_date", dataType: "date", format: "MM/dd/yyyy" }
I have the page displaying the JSON source data, which is:
[{"settlement_date"=>"2013-04-17", ...
But yet the igGrid displays "04/16/2013" instead of 4/17.
If I change the dataType to "string", then it displays "2013-04-17". So it appears to be Ignite's conversion to "date" that is screwing it up. (This would be ok, except that I can't format it now.)
Can someone please clue me in on what's going on and how I can fix it?
Thank you, that is very helpful and makes perfect sense. I guess I need to learn more about Javascript.
Hello,
JavaScript always creates Date objects in the local timezone but assumes the input string used to create the Date object is UTC. Therefore if you pass "2013-04-17" which is understood as 2013-04-17 00:00.000, in your local timezone UTC -N, the Date will be created as 2013-04-16 (24 - N):00.000 . Then igGrid will take the Date components using Date's API and as Day it'll display 16 instead of 17. By setting enableUTCDates to true you are telling the grid to use the UTC variants of Date's API which first add the timezone difference (and therefore restore the originally intended date-time) before returning the components.
I hope this is a bit less vague than my previous explanation. Please, don't hesitate to ask if you have any additional questions!
Best regards,
Stamen Stoychev
I don't entirely understand how UTC would cause a timeless date string to become yesterday. It's certainly not what one would reasonably expect.
I can't say this is a good answer, but it is an accurate one, I suppose.
What igGrid tries to do when the date is represented as a string in the data source is to initialize a new Date object using the string and then get its components with the Date API. Date assumes the string is representing an UTC date and therefore you should set enableUTCDates Grid option to true if you need the data source string and the string used by the formatter to be the same.
I hope this helps! Thank you for using Infragistics forums!