Question
· Jun 22, 2023

how to convert DATE to epoch

I am having a datatype DATE value from db 41966. And I want to convert it to epoch time.
Also, in case of DATETIME value how can I convert it to epoch.

Discussion (7)1
Log in or sign up to continue

#1 is correct

Your calculation #2 is seriously wrong.
reason
reading documentation you see
dformat -2 

$ZDATETIME returns an integer specifying the count of seconds from a platform-specific origin date/time. This is the value returned by the time() library function, as defined in the ISO C Programming Language Standard. For example, on POSIX-compliant systems this value is the count of seconds from January 1, 1970 00:00:00 UTC

And that's the mistake:
Your BirthDate is obviously considered as  LOCAL time
And therefore the difference you see reflects the time offset of your machine to UTC

-19800 sec => -5.5 hrs
system variable $ZTZ will show your offset to UTC in minutes  => -330
my guess: your machine is running at local time in India