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

Convert UTC datetime to localtime

Hi,

We have a dataset that contains UTC dates which we'd like to display as local dates (server local time). Is there a way to do this with the report designer using an expression column?

-Malcolm 

5 Replies

VS Vinoth Srinivasan Syncfusion Team May 31, 2019 06:27 PM UTC

Hi Malcolm, 

You can use the below expression in our report designer to convert the UTC datetime to local date time. 

=System.TimeZone.CurrentTimeZone.ToLocalTime(Parameters!DateParameter.Value) 
 

We have prepared a simple sample report based on this and it can be downloaded from the below location. 


Regards, 
Vinoth S. 



MV Malcolm van Staden June 1, 2019 08:01 AM UTC

Hi,

Thank you for that information. I see I said report designer, but what I meant to say was dashboard designer. I'll see if I can log this under the correct category.

-Malcolm


RN Renuka N Syncfusion Team June 3, 2019 07:27 AM UTC

Hi Malcolm, 
 
Thanks for your update.
 
Using Expression column, we can’t able to convert UTC time to local time in Dashboard Designer. You can achieve your requirement using code view option if you are using server types connection like SQL, MySQL and Postgres. 
 
For SQL server you can use DATEADD() function to add the hours or minutes in your date.  
Example:  If your local time is 2h ahead of Universal Coordinated Time, then you can add below line in your code view to achieve your requirement, 
DATEADD(hour, 2, [date time column]) as [LocalTime] 
 
If your local time is 5h 30m ahead of Universal Coordinated Time, then you can add below line in your code view to get the local time, 
DATEADD(mi, 330, [date time column]) as [LocalTime] 
Note: Here we have converted the 5 h 30 m to minutes (330) and then add the value with your date time column.  
 
Please refer below screen shot for your reference, 
  
 
For MySQL server, you can use DateAdd() function like as below,’ 
DATE_ADD([date column], INTERVAL 2 HOUR) as “LocalTime” 
 
For Postgres server, you can use DateADD() function like as below, 
[date column] + INTERVAL ‘2 hour’ as “LocalTime” 
 
Kindly refer below documentation link to know more about code view support in Dashboard Designer, https://help.syncfusion.com/dashboard-platform/dashboard-designer/connecting-to-data/connecting-through-custom-sql-query 
 
Please let us know if you need any further assistance.
 
Regards,
Renuka N.



MV Malcolm van Staden June 4, 2019 07:24 AM UTC

Hi Renuka,

Thank you for that information. Unfortunately we are using an API which provides JSON data. We are unable to change the data at the source and would much rather prefer to make use of the DATEADD function within the dashboard designer to display the field correctly. 

I will log a feature request to see if it's something that can be implemented.

Regards,
-Malcolm


DG Dhivyabharathi Govindaraj Syncfusion Team June 4, 2019 01:26 PM UTC

Hi Malcolm, 
 
We can achieve this requirement by using Code view in Dashboard Web Designer. 
 
Please follow the below steps to convert UTC to local time under Code view as shown below. 
 
DATEADD() function can be used to add the hours or minutes in date.  
 
Example:  If your local time is 2h ahead of Universal Coordinated Time, then you can add below line in your code view to achieve your requirement,  
DATEADD(hour, 2, [date time column]) as [LocalTime]  
  
If your local time is 5h 30m ahead of Universal Coordinated Time, then you can add below line in your code view to get the local time,  
DATEADD(mi, 330, [date time column]) as [LocalTime]  
Note: Here we have converted the 5 h 30 m to minutes (330) and then add the value with your date time column.   
  
Please refer below screen shot for reference, 
 
To connect On-premises Web Designer product kindly follow below steps, 
  1. Go to Dashboard Server and Click Add button. Choose Create-> Dashboard option,
 
 
  1. To connect Web API, enable Data Store Settings option of Dashboard Server,
 
  1. Choose Web API connection from Database list like as below and chose code view option to achieve your requirement.
 
 
 
Kindly refer below documentation link to know more about our Web Designer product, https://help.syncfusion.com/dashboard-cloud/dashboard-designer-walk-through . 
 
Currently we don’t have support to achieve your requirement using Expression function but we have logged a feature request on this and it can be tracked through our feedback portal below, https://www.syncfusion.com/feedback/5405/add-more-functions-for-expression-editor-in-syncfusion-dashboard-cloud 
 
Please let us know if you need any further assistance on this. 
 
Regards, 
Dhivya 
 


Loader.
Live Chat Icon For mobile
Up arrow icon