Date/Time Functions

Use the following functions to parse, format, and manipulate date, time, and datetime values anywhere in FME where expressions are supported. Unless stated otherwise, temporal arguments (date, time, datetime) must be in Standard FME Date/Time Format. For arithmetic support, see also DateTimeCalculator in the FME Workbench Transformers help.

Note: String arguments in date/time functions are automatically trimmed of leading and trailing whitespaces.

When a temporal arguments is processed, if the year, month, day, hours, minutes, and/or seconds are outside the supported range, the argument is rejected and the result is set to null. @DateTimeParse is the only date/time function that has an optional argument to repair parts that overflow supported ranges (except for years). For example, @DateTimeParse(20161332,%Y%m%d,repair) will repair the input date to 20170201.

Tip: Use @DateTimeParse to repair leap seconds and other temporal values containing parts that overflow supported ranges, such as datetime values generated by sensors and other mechanical devices.

Summary of Date/Time Functions

Function Description Examples
@DateTimeAdd() Datetime + Interval = Datetime

@DateTimeAdd(20170102, P1M) = 20170202

@DateTimeAdd(20170102, -P1M) = 20161202

@DateTimeCast()

Casts source type to destination type, if conversion is safe.

@DateTimeCast(20170102123000-08, time) = 123000-08:00

@DateTimeCast(20170132, date) = null

@DateTimeCast(20170001, date) = null

@DateTimeCreate() Creates datetime strings, unzoned or with UTC offset. @DateTimeCreate(2017,1,2,12,30,0,-08) = 20170102123000-08:00
@DateTimeDiff() Datetime – Datetime = Interval

@DateTimeDiff(20170201,20170101) = P1M

@DateTimeDiff(20170202, 20170201, seconds) = 86400

@DateTimeFormat() Formats FME datetime strings for consumption by writers and transformers. @DateTimeFormat(20170102,%B %d %Y) = January 02 2017
@DateTimeIntervalCreate() Creates interval strings in ISO 8601 duration format. @DateTimeIntervalCreate(1,0,0,0,0,0) = P1Y
@DateTimeIntervalNegate() Negates intervals. @DateTimeIntervalNegate(P1Y) = -P1Y
@DateTimeNow() Creates timestamps in local, local unzoned, or UTC time.

@DateTimeNow() = 20170203170000.1234567

@DateTimeNow(localUnzoned) = 20170203170000.1234567

@DateTimeNow(local) = 20170203170000.1234567-08:00

@DateTimeNow(utc) = 20170204010000.1234567+00:00

@DateTimeParse()

Parses arbitrary strings containing date time information into datetime strings in FME format.

Can be used for validation and repair. Can parse leap seconds by carrying the extra second forward so that all parts are brought in range.

@DateTimeParse(January 2 2017, %B %d %Y) = 20170102

@DateTimeParse(20170229,%Y%m%d,repair) = 20170301

Detailed Date/Time Function Descriptions

Date/Time Construction Functions

Date/Time Arithmetic Functions

Date/Time Parse/Format Functions

Format String Flags and Examples

Type Flag Meaning @DateTimeParse @DateTimeFormat
Year %Y Four-digit year, with range 1000 to 9999. @DateTimeParse(2017-01-02, %Y-%m-%d) = 20170102 @DateTimeFormat(20170102, %Y-%m-%d) = 2017-01-02
%y Two-digit year. Not supported. @DateTimeFormat(20170102, %y-%m-%d) = 17-01-02
Month %m Two-digit month, with range 01 to 12.

One digit month accepted.

@DateTimeParse(2017-1-2, %Y-%m-%d) = 20170102

@DateTimeFormat(20170102, %Y-%m-%d) = 2017-01-02
%b Abbreviated, 3-letter English month name. @DateTimeParse(Jan 2 2017,%b %d %Y) = 20170102 @DateTimeFormat(20170102, %b %d %Y) = Jan 02 2017
%B   @DateTimeParse(January 2 2017,%B %d %Y) = 20170102 @DateTimeFormat(20170102, %B %d %Y) = January 02 2017
Day %d Two-digit day of month, with range 01 to the last day of the month.

One digit day accepted.

@DateTimeParse(2017-1-2, %Y-%m-%d) = 20170102

@DateTimeFormat(20170102, %Y-%m-%d) = 2017-01-02
%j Three-digit day of year, with range from 001 to 365 (non-leap year) or 366 (leap year).

One and two digit days of year accepted.

@DateTimeParse(20171,%Y%j) = 20170101

@DateTimeFormat(20170101,%Y-%j) = 2017-001

@DateTimeFormat(20161231,%Y-%j) = 2016-366

%a Abbreviated, 3-letter weekday names. Not supported. Consider parsing using *. @DateTimeFormat(20170102, %a %b %d %Y) = Mon Jan 02 2017
%A Full weekday names. Not supported. Consider parsing using *. @DateTimeFormat(20170102, %A %B %d %Y) = Monday January 02 2017
Hours %H Two-digit hours, with range from 00 to 23.

One digit hours value accepted.

@DateTimeParse(8:30, %H:%M) = 083000

@DateTimeFormat(083000, %H:%M:%S) = 08:30:00
%I 12-hour clock, with range 01 to 12.

One digit hours value accepted.

@DateTimeParse(8:30PM, %I:%M%p) = 203000

@DateTimeFormat(003000, %I:%M %p) = 12:30 AM
%p AM/PM

AM/PM accepted, case insensitive.

@DateTimeParse(12:30am, %I:%M%p) = 003000

@DateTimeFormat(083000, %I:%M %p) = 08:30 AM
Minutes %M Two-digit minutes, with range 00 to 59.

One digit minutes value accepted.

@DateTimeParse(8:30, %H:%M) = 083000

@DateTimeFormat(083000, %H:%M:%S) = 08:30:00
Seconds %S Two-digit seconds, with range 00 to 59. Fractional seconds are supported up to nanosecond resolution.

One digit seconds value accepted.

@DateTimeParse(8:30:01.234, %H:%M:%S) = 083001.234

@DateTimeFormat(083059.123, %H:%M:%S) = 08:30:59.123
%s Seconds since the Unix Epoch time (1970-01-01 00:00:00+00:00). Fractional seconds are supported up to nanosecond resolution. If input is unzoned, it is assumed to be UTC time.

The seconds part must have at least a single digit. For example, "0.1" is considered a valid value for %s, but ".1" is not.

If %z is not specified, output is in UTC time (+00:00).

If %z is specified, the output datetime will have the same UTC offset as the input string.

@DateTimeParse(1.234,%s) = 19700101000001.234+00:00

@DateTimeParse(1.234-08:00,%s%z) = 19700101000001.234-08:00

@DateTimeFormat( 19700101000001.234,%s) = 1.234 @DateTimeFormat( 19700101000001+00:00,%s) = 1
Timezone %z UTC offset in the form +/-hh:mm.

UTC offset in the form +/-hh, +/-hhmm, or +/-hh:mm, or Z for Zulu time which is +00:00.

@DateTimeParse(8:30-08,%H:%M%z) = 083000-08:00

@DateTimeParse(03:04:05Z,%H:%M:%S%z) = 030405+00:00

@DateTimeFormat(000000-08:00,%T%z) = 00:00:00-08:00
Shortcuts %T Equal to %H:%M:%S. @DateTimeParse(03:04:05,%T) = 030405 @DateTimeFormat(000000,%T) = 00:00:00
FME

Auto parses input that is in the Standard FME Date/Time Format, and repairs overflow parts if the repair argument is set.

It can be combined with the flag ISO, separated by the | character.

To disambiguate this shortcut from a regular text string of the same content, when FME and ISO are specified, there must be no other format flags present.

@DateTimeParse(030460-0800, FME, repair) = 030500-08:00

@DateTimeParse(030460-0800, FME|ISO, repair) = 030500-08:00

Not supported.
ISO

Auto parses/formats input into ISO datetime format.

To disambiguate this shortcut from a regular text string of the same content, when ISO is specified, there must be no other format flags present.

@DateTimeParse(2017-01-02, FME | ISO) = 20170102

@DateTimeParse(03:04:60,ISO,repair) = 030500

@DateTimeFormat(20170102, ISO) = 2017-01-02

@DateTimeFormat(20170102030405-08,ISO) = 2017-01-02T03:04:05-08:00

Wildcard Character * A single word, delimited by a whitespace or the start/end of string. @DateTimeParse(On Monday January 23 2017,* * %B %d %Y) = 20170123 Not supported.
? A single character.

@DateTimeParse(January 23rd 2017,%B %d?? %Y) = 20170123

@DateTimeParse(LC80460262015110LGN00, LC???????%Y%jLGN??) = 20150420

Not supported.
$ End of input. Used to ensure that the input fully matches the format string.

@DateTimeParse(2017-01-02, %Y-%m-%d$) = 20170102

@DateTimeParse(2017-01-02 and then, %Y-%m-%d$) = null

Not supported.
Special Character %% The % character. @DateTimeParse(2017%01%05,%Y%%%m%%%d) = 20170105 Not supported.
%* The * character. @DateTimeParse(*** 2017-01-05,%*%*%* %Y-%m-%d) = 20170105 Not supported.
%? The ? character. @DateTimeParse(On Jan 2 2017?,* %b %d %Y%?) = 20170102 Not supported.
%$ The $ character. @DateTimeParse(2017$01$02,%Y%$%m%$%d) = 20170102 Not supported.
Regular Character Any Any character that is not prepended by % is considered a regular character. Case sensitivity is respected.

@DateTimeParse(On Jan 23 2017, On %b %d %Y) = 20170123

@DateTimeParse(On Jan 23 2017, on %b %d %Y) = null

@DateTimeFormat(20170102,On %B %d %Y) = On January 02 2017