Search | | Contact Us | Resource Center Login | Home|

How do you get the current Coordinated Universal Time (UTC)?

a. %datetime()
b. %datetime(%timezone())
c. %datetime() - %timezone()
d. ^d(%datetime()) - %timezone() * 60000000

Coordinated Universal Time (UTC) is roughly equivalent to Greenwich Mean Time – the time at the Greenwich meridian in the UK without taking daylight saving time into account.  Calling the Synergy-supplied function %datetime without arguments returns the local system time, so unless your computer time is set to UTC, (a) is not correct.  The new Synergy-supplied function %timezone returns the number of minutes to add to UTC to get local system time, based on the system settings for time zone and daylight saving time.  But you can’t simply subtract this value from the result of %datetime (c).  The result of %datetime() is alphanumeric, and includes seconds and microseconds.  But even correcting those differences (d) is not sufficient.  Since there are only 60 minutes in an hour, and only 24 hours in a day, the subtraction would fail to remove/add enough hours and days.  To perform the math properly, you’d have to either break apart the value, subtract the minutes (handling underflow), and put it back together; or convert both values to microseconds, subtract, and convert back to datetime.  Fortunately, you don’t need to go to all that trouble.  The %datetime function accepts an optional argument specifying the UTC offset, which just happens to match the scale returned by %timezone, and so (b) is the correct answer.

This example demonstrates two new features in Synergy/DE version 9.3.  The new function %timezone returns the UTC offset (and optionally the time zone and a flag indicating whether daylight savings time is in effect as well), and a new, optional argument to %datetime specifies the UTC offset.  These are just two of the many new features now available in version 9.3.  If you haven’t yet upgraded, now is the Time.

More information about News and Events

Contact Synergex to learn more about  News and Events