简体   繁体   中英

Converting a timestamp string to UNIX timestamp in MonetDB

I'd like to convert a timestamp like "2018-02-14 23:59:59" to a UNIX timestamp. I found that the opposite is possible using select sys.epoch(unix_timestamp); . The functions str_to_date , str_to_time or str_to_timestamp are of no help, even if I specify the format string "%s" as seen here .

In other words, I'm looking for the MonetDB equivalent of the MySQL function UNIX_TIMESTAMP() .

Found the solution:

select sys.epoch(str_to_timestamp('2018-02-15 10:04:00', '%Y-%m-%d %H:%M:%S'));

1518689040

Obviously, if you need this in milliseconds, just multiply by 1000 like so:

select sys.epoch(str_to_timestamp('2018-02-15 10:04:00', '%Y-%m-%d %H:%M:%S')) * 1000;

How I found it, in case anyone has a similar problem in the future:

You can view all system functions using:

select * from sys.functions;

A prettier solution can be found here: Is there a way to view MonetDB Function signatures

It turns out the epoch function can take a timestamp as a parameter.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM