Skip to main content
Solved

FME 2016 how to subtract 10 hours from a DATETIME string

  • February 14, 2018
  • 7 replies
  • 149 views

nicholas
Contributor
Forum|alt.badge.img+13

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.

View original
Did this help you find an answer to your question?

7 replies

nielsgerrits
VIP
Forum|alt.badge.img+54
  • 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
Influencer
  • 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
  • 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+54
davidrich wrote:

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 15in input
NameErrorglobal 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
  • February 16, 2018
nielsgerrits wrote:
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 15in input
NameErrorglobal 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+54
davidrich wrote:
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
  • February 16, 2018
nielsgerrits wrote:
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"

Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings