Function StringToMoment(Format, Unit, ReferenceDate, Timeslot)

StringToMoment

The function StringToMoment converts a given time string (in a free time format) to the elapsed time with a respect to a specific reference date.

StringToMoment(
     Format,             ! (input) a string expression
     Unit,               ! (input) a time unit
     ReferenceDate,      ! (input) a string expression
     Timeslot            ! (input) a string expression
     )

Arguments

Format

A string that holds the date and time format used in the fourth argument Timeslot. Valid format strings are described in Format of Time Slots and Periods

Unit

The time unit that is used to return the elapsed time.

ReferenceDate

A string that holds the begin date using the fixed format for date and time, see paragraph Reference date format of the Language Reference.

Note

Depending on the option use UTC forCaseAndStartEndDate, reference dates are with respect to

  • value on : timezone 'UTC' or

  • value off: timezone 'local'.

Timeslot

A string representing a specific date and time moment using the format specified in the first argument Format.

Return Value

The result of StringToMoment is the elapsed time in unit between reference-date and date.

Example

The code:

block where use_UTC_forCaseAndStartEndDate := 'on' ;
    _p_noSec1 := StringToMoment(
        Format        :  "%c%y-%m-%d %H:%M:%S%TZ('UTC')",
        Unit          :  [s],
        ReferenceDate :  "2020-01-01 09:30:30",
        Timeslot      :  "2020-01-01 09:30:58");
    display _p_noSec1 ;
endblock ;
block where use_UTC_forCaseAndStartEndDate := 'off' ;
    _p_noSec2 := StringToMoment(
        Format        :  "%c%y-%m-%d %H:%M:%S%TZ('local')",
        Unit          :  [s],
        ReferenceDate :  "2020-01-01 09:30:30",
        Timeslot      :  "2020-01-01 09:30:58");
    display _p_noSec2 ;
endblock ;

Will result in:

_p_noSec1 := 28 [s] ;

_p_noSec2 := 28 [s] ;

See also

The functions MomentToString, CurrentToMoment.