We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

DateTimePicker return UTC Date/Time?

The app is using a legacy db where all the datetime fields are local (not using UTC as basis).  I've notice that the DateTimePicker returns the date/time  selected in the control  converted to UTC time upon update to the controller.  i.e. A user selects 1/1/19 12:00 in the control, but the controls returns 1/1/19 20:00 to the controller upon update.  I want it to just return 1/1/19 12:00.  Can I do that on the control or do I have to convert it back at the controller manually?

Mike

5 Replies

DL Deepa Loganathan Syncfusion Team January 11, 2019 12:56 PM UTC

Hi Daniel,  
 
Thanks for contacting Syncfusion support.  
 
We have investigated the reported issue in Datetimepicker and tried to reproduce the reported issue with a simple test sample. Sorry, but we were unable to reproduce it while posting the selected value to server from DatetimepickerFor control and can confirm that the same value was posted in the controller.  
 
Please find the test sample from the below link.  
 
 
So kindly share us the below details that would help us to analyze and isolate the root cause of this issue.  
 
1.      View page, Model, ViewModel and controller pages of your application. 
2.      Are you using any stored procedure that might convert the DateTime values to its equivalent UTC?  
3.      Database language used in your application 
4.      A video that demonstrates the conversion in code behind, if possible 
 
Regards,  
Deepa L. 



ML Michael Lambert January 11, 2019 09:22 PM UTC

Hi,
I'm using SQL as the DB backend. When the datasource is sent to the Grid the DateStart.Kind (field var) = unspecified, but on the update post the DateStart.Kind is changed to UTC which seem to lead to a timezone issue.

Please see attached for screen captures and code.

Thanks,
Mike

Attachment: SyncFDateIssue_e631a344.zip


MS Madhu Sudhanan P Syncfusion Team January 18, 2019 10:32 AM UTC

Hi Michael, 

Sorry for the delayed response. 

We have validated the provided information and we suggest you to use the below way to achieve your requirement. In the below code example, we have converted date object into ISO string by using DataUtil.dateparse method in actionBegin event of Grid. 

Please refer the below code example for more information. 

<div> 
    <ejs-grid id="Grid" actionBegin="begin" toolbar="@(new List<string>() {"Delete" ,"Add", "Update", "Cancel" })" allowPaging="true"> 
        <e-grid-editsettings allowDeleting="true" allowEditing="true" allowAdding="true"></e-grid-editsettings> 
        <e-grid-columns> 
             . . . . .  
            <e-grid-column field="DateStart" headerText="OrderDate" type="dateTime" edit="@(new {create = "created", read = "readd", destroy = "destroyd", write = "writed"})" minWidth="20" maxWidth="500"></e-grid-column> 
        </e-grid-columns> 
    </ejs-grid> 
</div> 
 
<script> 
 
    function begin(args) { 
        if (args.requestType === 'save') { 
            // you can also convert date object as ISO string using below method to resolve the problem. 
 
            args.data['DateStart'] = ej.data.DataUtil.dateParse.addSelfOffset(new Date(args.data['DateStart'])).toISOString(); 
        } 
    } 

Regards, 
Madhu Sudhanan P 



ML Michael Lambert January 22, 2019 07:03 PM UTC

Thanks Madh, that works!


MS Madhu Sudhanan P Syncfusion Team January 23, 2019 05:56 AM UTC

Hi Michael, 
We are glad that your requirement has been achieved. 
Regards, 
Madhu 


Loader.
Live Chat Icon For mobile
Up arrow icon