Problem with date-time columns in grid

I have a grid (with RemoteUpdateAdapter) with date-time columns, defined like this:

                          edit-type="DateTimePicker"
                          [email protected]
                          format="{0:M/d/yyyy h:mm tt}" />

Both me and the server are in Pacific Daylight Time (-7:00).

If I select a value like 10/9/2018 8:00 AM, it's sent to the server as 10/9/2018 3:00 PM, i.e., in UTC. However, when the time comes back from the server on a page refresh, it's displayed as 3:00 PM, not 8:00 AM, i.e., not adjusted for time zone. In the Schedule component, there's an option "apply-time-offset="false"" which makes it not adjust the time zone when posting. However, I can't find a similar property anywhere on the Grid or in the DateTimePicker.

At this point, I don't care if the time is stored on the server as UTC or local time (as long as I know which to expect). However, I really need the editor to interpret the time properly. Is there a way to do this?


EDIT/ANSWER:

I'm realizing that the problem is that the time is sent to the server as "ValidFrom
: 2017-10-08T22:00:00Z" and returned as "ValidFrom: 2017-10-08T22:00:00". I.e., the problem lies in sql server/entity framework not storing & retrieving the timezone properly.

After some searching, I found a solution: define the fields in the model as DateTimeOffset, instead of DateTime. This will store the timezone in the server, and return it properly.

brian

3 Replies

MS Mani Sankar Durai Syncfusion Team October 10, 2017 12:11 PM UTC

Hi Brain, 

Thanks for the update. 

We are happy to hear that your problem has been solved. 

Also please refer the below link which helps to solve the server time zone 

Please let us know if you need further assistance. 

Regards, 
Manisankar Durai. 



CH Chris April 3, 2018 08:18 PM UTC

Hi,

I had a very similar problem to the original poster.  I thought I would post how I got around it in case it helps anyone else.

I found that changing the fields in the model to DateTimeOffset didn't work as it was storing the timezone as UTC not mountain time.  This is an internal web app so I don't have to worry about globalization.

In my model the field is set up as "DateTime?".  (It can be null).  I wrote an extension method.  It looks like this:

    public static class DateTimeExtensions
    {
        public static DateTime? GetLocalDateTime(this DateTime? dateTimeVal)
        {
            if (dateTimeVal != null)
            {
                DateTime dateTime = new DateTime();
                dateTime = dateTimeVal.GetValueOrDefault().ToLocalTime();

                return dateTime;
            } else
            {
                return null;
            }
        }
    }

In the update method you do something like this:

myUpdObj.DateTimeField = myCRUDModelObj.DateTimeField.GetLocalDateTime();

In my testing it is working as desired.  It is saving the datetime to the database correctly and retrieving it as expected.

Chris




KM Kuralarasan Muthusamy Syncfusion Team April 4, 2018 07:35 AM UTC

Hi Chris, 

Thanks for your suggestion. If you have any other query please get back to us. 

Regards, 
Kuralarasan M. 


Loader.
Up arrow icon