Skip to main content

The Documentation for the @DateTimeFormat Function clearly states that parsing ISO 8601 format is supported:

“Formats FME or ISO date, time, and datetime strings into a custom format [...] Arguments: <datetime> [...] Date, time, or datetime string in Standard FME Date/Time Format or ISO 8601 date and time format.”, so using PT1H as datetime Argument should be valid.

But the Parsing of ISO 8601 date and time format fails:

AttributeManager: Failed to parse 'PT1H' as a datetime value. For FME datetime syntax, please see http://docs.safe.com/fme/html/FME_Desktop_Documentation/FME_Workbench/!Transformer_Parameters/standard_fme_date_time_format.htm . For ISO datetime syntax, please see http://docs.safe.com/fme/html/FME_Desktop_Documentation/FME_Workbench/!Transformer_Parameters/standard_fme_date_time_format.htm#ISO-8601-Duration-Format

Failed to evaluate expression '@DateTimeFormat(PT1H,%H)'. Result is set to null

 

FME Form 2025.1.2.0 (20250829 - Build 25630)

P1TH is a duration not a datetime. The DateTimeCalculator will allow you to use ISO Durations


P1TH is a duration not a datetime. The DateTimeCalculator will allow you to use ISO Durations

I know that it’s an duration, an ISO 8601 duration to be exact, which should be supported by the @DateTimeFormat Function according to the documentation.


Hi ​@_fabian_ ,

No, the @DateTimeFormat function doesn't support ISO 8601 duration, does support ISO 8601 date and time. See the documentation carefuly.

“Date, time, or datetime string in Standard FME Date/Time Format or ISO 8601 date and time format.” -- Date/Time Functions


Thanks for clarifying. I was under the impression that ISO 8601 exclusively defines the duration/period notation (because it only appears as such in the FME documentation). Actually ISO 8601 defines both the period Notation P(n)Y(n)M(n)DT(n)H(n)M(n)S as well as the Date Time Notation YYYY-MM-DD H:M:S (which is kind of wild that one ISO norm defines multiple things, it isn’t even clearly defined on the iso.org website).

 

So what is the best way to convert from a period into a H:M:S notation?


An FME way for durations less than 24 hours

 

Over 24 hours you would need to do the maths to go from seconds to hours minutes seconds and skip the DateTimeConverter since this won’t cope with anything over 24 hours


I’m also assuming you’re not dealing with durations that include months.

If it was me, I’d probably just try and do the conversion using regular expressions


I’m also assuming you’re not dealing with durations that include months.

If it was me, I’d probably just try and do the conversion using regular expressions

I should only deal with hours, not even days. I hoped FME would have a native function to convert the format but maybe there is a python library I could use as well (or just KISS and use RegEx)


For your reference, since the FME Date/Time Functions generally support not only datetime and date values but also time values, this workflow should work as well. Assuming that the attribute "_duration" stores a duration value in ISO8601 format e.g. PT1H and the value is less than 24 hours.

And, it's equivalent to this expression.

@DateTimeFormat(@DateTimeAdd(000000,@Value(_duration)),iso)