$ZDATETIME($h,3,1,3)
Hi,
I am using this "$ZDATETIME($h,3,1,3)" and getting response as 2024-09-03 12:07:45.000
But I need proper values at the end instead of zeros (000)
Something like below -
2024-09-03 12:07:45.658
Comments
If you replace $h with $NOW(), this should do as you need
.png)
However there is a caveat with regards to Timezones mentioned in the online documentation that you may want to review to ensure it works as you'd expect and need.
I have tried this but it is not giving current time , an hour back it displays.
This will be that caveat I warned of which is detailed in the documentation.
You could do something like:
Write $ZDATETIME($h_"."_$P($NOW(),".",2),3,1,3)
Which takes the value of $H and appends the milliseconds from $NOW() to then form your datestamp:
.png)
However the documentation I linked to warns that there can be a discrepancy between $H and $NOW() so this approach could then lead to your timestamp being off by up to a second. As you are trying to work to the level of milliseconds, I suspect accuracy is very important and therefore I would not recommend this approach.
Take a look here and see if this example of comparing $h, $ZTIMESTAMP, and $NOW() helps, and the example of converting from UTC to the local timezone helps.
The link in my last reply actually contains the answer, which is always useful. I have tweaked it slightly so that it's a single line, but the output is the same.
To get the current date and time with milliseconds, you can do the following:
WRITE$ZDATETIME($ZDATETIMEH($ZTIMESTAMP,-3),3,1,3)This is:
- Starting with the output of $ZTIMESTAMP
- Converting to a $HOROLOG format adjusted for your local timezone using $ZDATETIMEH
- Converting to the desired format using $ZDATETIME
I hope this helps!
Together with $now() and timezone adjustment you can have the desired result
for time=$h, $now($ztz-$s($SYSTEM.Util.IsDST():60,1:0)) write time,?20,$zdt(time,3,1,3),!
// assuming 60 min summertime offset//// you should get an output like thisL67086,833342024-09-0323:08:54.00067086,83334.13410262024-09-0323:08:54.134There is an (old) undocumented function which gives the $h value with several decimal places, unfortunately the recommended replacement is more or less the above solution instead of a simple $zlts (z-local-timestamp).
By the way, if you need again and again a local timestamp with decimals, just create a user defined system variable. Make a one line entry into the %ZLANGV00.mac routine:
%ZLANGV00 ; User defined (system) variables// Local timestamp with decimals
ZLTS() quit$now($ztz-$s($SYSTEM.Util.IsDST():60,1:0))
You can use whatever name you want as long as it starts with Z, contains uppercase chars only and do not conflict with existing names. Use it as a standard $-variable
write$zlts, $zdt($zlts,3,1,3)
67086,85681.0927462024-09-0323:48:01.092