04-30-2025 05:57 AM
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
05-05-2025 03:33 AM - edited 05-05-2025 03:35 AM
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
05-05-2025 05:28 AM
Thanks Leonard. great to see your response.
I am trying to achieve with VBscript. is there anything could you suggested here with VBscript?
05-05-2025 05:45 AM
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
05-05-2025 05:56 AM
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
05-05-2025 06:05 AM - edited 05-05-2025 06:08 AM
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
05-05-2025 06:41 AM
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.
05-06-2025 02:01 AM
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
05-07-2025 01:54 AM
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