Skip to main content

I have a DATETIME string of the format 20180311140001

Which is YYYYMMDDHHMMSS

How can I subtract 10 hours?

Note: I have FME2016, so I lack the DateTimeCalculator

Once I have calculated the above, I still need to do more tweaking, but that is string manipulation, not a math calculation

Use DateFormatter to convert from %Y%m%d%H%M%S to %s (Count of seconds since the epoch, expressed as a decimal integer.)

Subtract 36000 (60*60*10) seconds.

Convert back to %Y%m%d%H%M%S.

subtract-from-datetime-2016.fmw

Be aware: This deliberately and consciously ignores leap seconds.


Alternatively, you can also use the "DateTimeCalculator" custom transformer from FME Hub. It has been deprecated since its name is the same as the regular DateTimeCalculator in FME 2017, but it's still available in FME 2016 and earlier.


Basically the same as @nielsgerrits but all within a python caller transformer.

Except converting the string to python datetime and using timedelta to remove the 10 hours

subtract-from-datetime-python-2016.fmw


Basically the same as @nielsgerrits but all within a python caller transformer.

Except converting the string to python datetime and using timedelta to remove the 10 hours

0684Q00000ArKQNQA3.pngsubtract-from-datetime-python-2016.fmw

Hey @davidrich are you sure this works? When I run this workspace it fails.

 

2018-02-16 06:51:30|   0.3|  0.0|WARN  |Python Exception <NameError>: global name 'NewTime' is not defined
2018-02-16 06:51:30|   0.3|  0.0|WARN  |Traceback (most recent call last):
  File "<string>", line 15, in input
NameError: global name 'NewTime' is not defined
2018-02-16 06:51:30|   0.3|  0.0|ERROR |Error encountered while calling method `input'
2018-02-16 06:51:30|   0.3|  0.0|FATAL |f_7(PythonFactory): PythonFactory failed to process feature 

Hey @davidrich are you sure this works? When I run this workspace it fails.

 

2018-02-16 06:51:30|   0.3|  0.0|WARN  |Python Exception <NameError>: global name 'NewTime' is not defined
2018-02-16 06:51:30|   0.3|  0.0|WARN  |Traceback (most recent call last):
  File "<string>", line 15, in input
NameError: global name 'NewTime' is not defined
2018-02-16 06:51:30|   0.3|  0.0|ERROR |Error encountered while calling method `input'
2018-02-16 06:51:30|   0.3|  0.0|FATAL |f_7(PythonFactory): PythonFactory failed to process feature 
Sorry I had renamed a value and didn't change all of them.

 

subtract-from-datetime-python-2016.fmw

 

 


Sorry I had renamed a value and didn't change all of them.

 

subtract-from-datetime-python-2016.fmw

 

 

Thanks, learned something new today 🙂
Thanks, learned something new today :-)
No problem, also if you ever want to do more complex string input or output, I use this http://strftime.org/ which is all the different inputs or outputs other than "%Y%m%d%H%M%S" such as "%-I:%M:%S %p %d %B %y" which is "7:06:05 AM 30 September 13"

Reply