Skip to main content
Solved

FME 2016 how to subtract 10 hours from a DATETIME string

  • February 14, 2018
  • 7 replies
  • 170 views

nicholas
Contributor
Forum|alt.badge.img+14

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

Best answer by nielsgerrits

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.

This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

7 replies

nielsgerrits
VIP
Forum|alt.badge.img+60
  • 2940 replies
  • Best Answer
  • February 14, 2018

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.


takashi
Celebrity
  • 7843 replies
  • February 14, 2018

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.


Forum|alt.badge.img
  • 48 replies
  • February 14, 2018

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


nielsgerrits
VIP
Forum|alt.badge.img+60
  • 2940 replies
  • February 16, 2018

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 

Forum|alt.badge.img
  • 48 replies
  • February 16, 2018
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

 

 


nielsgerrits
VIP
Forum|alt.badge.img+60
  • 2940 replies
  • February 16, 2018
Sorry I had renamed a value and didn't change all of them.

 

subtract-from-datetime-python-2016.fmw

 

 

Thanks, learned something new today :-)

Forum|alt.badge.img
  • 48 replies
  • February 16, 2018
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"