DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

UTC time to user local time

Hi,

Wanted to display the time information in report.

would like to convert the UTC time information stored in custom property to local time based on timezone information of the computer running DIAdem and display local time in report.

 

regards,

Durai

0 Kudos
Message 1 of 9
(975 Views)

Hi Durai,

 

There is the rtt function which converts a non UTC timestamp (seconds since 1/1/0000) to a nicely formatted time string. However this is not applicable here since it ignores timezones (it assumes your timestamp is in the same timezone as you).

 

I would recommend creating a custom script in DIAdem, which you run once before creating the report. See below an example script to read the custom property and create a new property with the local time string in Python. The script has access to all channel groups / channels that are loaded into your data portal (called "Root" in the script). Make sure to load all relevant channel groups / channels so the script can find them.

 

from datetime import datetime, timezone
from DIAdem import Application as dd

GROUP_NAME = "group_name"  # select which group to act on
PROP_NAME = "prop_name"  # specify property name containing timestamp

for channel in dd.Data.Root.ChannelGroups(GROUP_NAME).Channels:
    if channel.Properties.Exists(PROP_NAME):
        prop = channel.Properties(PROP_NAME)
        utc_dt = datetime.fromtimestamp(prop.Value, tz=timezone.utc)
        local_dt = utc_dt.astimezone()
        local_str = local_dt.strftime('%Y-%m-%d %H:%M:%S %Z')

        # this will add the new custom property called
        # LocalTime with the local time string as value
        channel.Properties.Add("LocalTime", local_str)

 

 

 

Let me know if it helps, or if you have more questions!

 

Best regards

Leonard

 

0 Kudos
Message 2 of 9
(909 Views)

Thanks Leonard. great to see your response.
I am trying to achieve with VBscript. is there anything could you suggested here with VBscript?

0 Kudos
Message 3 of 9
(899 Views)

Hi Durai,

 

so you want to port it to VBscript and not use the Python version?

 

Note that both, python and VB, are equivalent here:

1. create the custom script in script editor

2. run the script to modify the data in the data portal

Just the syntax is different...

 

If you want I could write a VBscript version, but I would need to quickly check the VBscript API. Let me know if that would help you.

 

Best regards

Leonard

0 Kudos
Message 4 of 9
(892 Views)

Thanks again Leonard,

 

I tried to do it with VBscript, but I am unsuccessful. I am not able to find any VBscript API that can help me to convert UTC time to user local time. Even I am not able to identify the user time zone information using VBscript which is needed for the task.

 

Example:

UTC Time in custom property: 05-05-2025 10:19:00

user from India: Equivalent Local time to reflect in report : 05-05-2025 15:49:00 IST

0 Kudos
Message 5 of 9
(889 Views)

Hi Durai,

 

VBscript doesnt seem to expose timezone conversion functionality. Why dont you use Python instead?

 

If your time offset is always constant (your local time is always india) then you could also just work with a fixed offset. This would require you to convert the time string to a timestamp beforehand.

 

Best regards

Leonard

0 Kudos
Message 6 of 9
(885 Views)

Hi Leonard,

We want to use only VBscript at the moment. Also, I am developing script that will be used by global users, so I can make fixed offset.

 

want to achieve everything in VBscript alone. I am still exploring yet to be succeeded.

0 Kudos
Message 7 of 9
(879 Views)
Dim dateTime
Dim duraiDateTime, duraiUTCTime,duraiLocalTime

Set dateTime = CreateObject("WbemScripting.SWbemDateTime")

duraiDateTime = "05-05-2025 10:19:00"

Call dateTime.SetVarDate(CDate(duraiDateTime),False)

duraiUTCTime = dateTime.GetVarDate(false)
duraiLocalTime = dateTime.GetVarDate(true) 

Call logfilewrite("Durai's UTC Time:  " & duraiUTCTime )
Call logfilewrite("Durai's Local Time (+8 for Malaysia) : " & duraiLocalTime)

set dateTime=Nothing

You may give this script a quick try

Best Regards,
Soo Kin Wah
Technical Support Engineer
NI
0 Kudos
Message 8 of 9
(837 Views)

Hi Soo kin,

 

Its working fine , great.

 

Is it possible for me to have user time zone information after the time?

 

Eg: 07-05-2025 12:53:00 IST

 

0 Kudos
Message 9 of 9
(809 Views)