util.Datetime.toSecondsSinceEpoch()

util.Datetime.toSecondsSinceEpoch() converts a DATETIME value to a FLOAT value showing the number of seconds since Unix epoch.

Syntax

util.Datetime.toSecondsSinceEpoch(datetime)

Parameters

datetime

a DATETIME value for that you want to get number of seconds since Unix Epoch

Usage and examples

util.Datetime.toSecondsSinceEpoch() takes a DATETIME value and returns a FLOAT value showing the number of seconds since Unix epoch (1970-01-01 00:00:00 GMT).

Unix epoch is a system for describing instants in time, defined as the number of seconds that have elapsed since 00:00:00 Coordinated Universal Time (UTC), Thursday, 1 January 1970, not counting leap seconds.

The resulting value is a whole number if the source is a DATETIME YEAR TO SECOND, or a floating-point number if the source is a DATETIME YEAR TO FRACTION(N) (this is so in order to include the fractional part).

example code #1

 

MAIN

  DEFINE epoch VARIANT

    DISPLAY CURRENT

    LET epoch = util.Datetime.toSecondsSinceEpoch(CURRENT)

    DISPLAY "Unix epoch time:  ", epoch

  CALL fgl_getkey()

END MAIN

obtained results #1

example code #2

MAIN

    DISPLAY "2017-02-23 17:15:56.12"

    DISPLAY "Unix epoch time for DATETIME YEAR TO SECOND:  "

    DISPLAY util.Datetime.toSecondsSinceEpoch(DATETIME(2017-02-24 17:15:56) YEAR TO SECOND)

    DISPLAY "Unix epoch time for DATETIME YEAR TO FRACTION(2):  "

    DISPLAY util.Datetime.toSecondsSinceEpoch(DATETIME(2017-02-24 17:15:56.12) YEAR TO FRACTION(2))

  CALL fgl_getkey()

END MAIN

obtained results #2

 

 

Contact Us

Privacy Policy

Copyright © 2024 Querix, (UK) Ltd.