Skip to main content
Solved

Calculate UTC time in FME 2014


fikusas
Contributor
Forum|alt.badge.img+5

How to get UTC time in FME 2014? TimeStamper gives local time >>

When in DateTimeCalculator I'm subtracting hours from local time to get UTC time, but this won't work after Daylight Saving Time begins.

Best answer by ebygomm

fikusas wrote:

This worked for some time, but stopped recently. Maybe it is possible convert local time (with Daylight savings adjusted) to UTC via Python script?

Not sure whether this will work in 2014, I think it should. But you can use an InlineQuerier to return UTC

e.g. 

select datetime('now'as utc

Worth a try

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

14 replies

redgeographics
Celebrity
Forum|alt.badge.img+49

Not an answer to your question I'm afraid, but if you have the chance to update to FME 2019 that would be highly recommended, the date/time functionality is vastly improved in recent versions.


fikusas
Contributor
Forum|alt.badge.img+5
  • Author
  • Contributor
  • January 22, 2020
redgeographics wrote:

Not an answer to your question I'm afraid, but if you have the chance to update to FME 2019 that would be highly recommended, the date/time functionality is vastly improved in recent versions.

Yeah, I know it's easy to pull it in 2019. But I need to get UTC in 2014...


takashi
Influencer
  • January 22, 2020

I'm not sure this works in your timezone, but Tcl has a function to convert a local time to other timezone including UTC. Try setting this expression to the Tcl Expression parameter in the TclCaller. Assuming the input "timeposition" (local time in your machine) is formatted with the ISO standard date/time format (%Y-%m-%dT%H:%M:%S).

clock format [clock scan [FME_GetAttribute timeposition] -format %Y-%m-%dT%H:%M:%S] -format %Y-%m-%dT%H:%M:%S -timezone :UTC

See here to learn more about the clock command in Tcl: https://www.tcl.tk/man/tcl8.5/TclCmd/clock.htm

And available timezone names are here:  https://wiki.tcl-lang.org/page/timezone 

Again, I don't know if Tcl supports your timezone with daylight saving time. Please make enough test.


robotix
Contributor
Forum|alt.badge.img+10
  • Contributor
  • January 22, 2020

I have a solution but it requires a couple more steps in your process. Not super elegant but it works.

We occasionally use a date reference table in a database to determine daylight savings, Then reference the table to determine how to calculate time. Subtract or add so many hours depending upon start and end of daylight savings. The number of hours to add or subtract is dependent upon your time zone.

You could always create a spreadsheet with something similar. Compare to dates in the spreadsheet and in your transformation(s) say IF datetimenow()>dst_start and datetimenow()<dst_end then +- hours.

We reference the year then determine. Here is a snippet of our table.

 

Best wishes.


fikusas
Contributor
Forum|alt.badge.img+5
  • Author
  • Contributor
  • September 21, 2020
takashi wrote:

I'm not sure this works in your timezone, but Tcl has a function to convert a local time to other timezone including UTC. Try setting this expression to the Tcl Expression parameter in the TclCaller. Assuming the input "timeposition" (local time in your machine) is formatted with the ISO standard date/time format (%Y-%m-%dT%H:%M:%S).

clock format [clock scan [FME_GetAttribute timeposition] -format %Y-%m-%dT%H:%M:%S] -format %Y-%m-%dT%H:%M:%S -timezone :UTC

See here to learn more about the clock command in Tcl: https://www.tcl.tk/man/tcl8.5/TclCmd/clock.htm

And available timezone names are here:  https://wiki.tcl-lang.org/page/timezone 

Again, I don't know if Tcl supports your timezone with daylight saving time. Please make enough test.

This worked for some time, but stopped recently. Maybe it is possible convert local time (with Daylight savings adjusted) to UTC via Python script?


takashi
Influencer
  • September 21, 2020
fikusas wrote:

This worked for some time, but stopped recently. Maybe it is possible convert local time (with Daylight savings adjusted) to UTC via Python script?

@fikusas​ , are you still using FME 2014?


fikusas
Contributor
Forum|alt.badge.img+5
  • Author
  • Contributor
  • September 21, 2020
fikusas wrote:

This worked for some time, but stopped recently. Maybe it is possible convert local time (with Daylight savings adjusted) to UTC via Python script?

Yeah, still using FME 2014. There's no doubt how to do it in newer versions.


ebygomm
Influencer
Forum|alt.badge.img+32
  • Influencer
  • Best Answer
  • September 21, 2020
fikusas wrote:

This worked for some time, but stopped recently. Maybe it is possible convert local time (with Daylight savings adjusted) to UTC via Python script?

Not sure whether this will work in 2014, I think it should. But you can use an InlineQuerier to return UTC

e.g. 

select datetime('now'as utc

Worth a try


fikusas
Contributor
Forum|alt.badge.img+5
  • Author
  • Contributor
  • September 21, 2020
fikusas wrote:

This worked for some time, but stopped recently. Maybe it is possible convert local time (with Daylight savings adjusted) to UTC via Python script?

It works, but returns no geometry. I'm reading some points and need to assign UTC time to those points.


ebygomm
Influencer
Forum|alt.badge.img+32
  • Influencer
  • September 21, 2020
fikusas wrote:

This worked for some time, but stopped recently. Maybe it is possible convert local time (with Daylight savings adjusted) to UTC via Python script?

I'm not sure with your workflow whether you can generate the utc time with the inline querier then merge onto your points, alternatively you can extract your point geometry to an attribute and then rebuild it again after the inlinequerier.


fikusas
Contributor
Forum|alt.badge.img+5
  • Author
  • Contributor
  • September 21, 2020
fikusas wrote:

This worked for some time, but stopped recently. Maybe it is possible convert local time (with Daylight savings adjusted) to UTC via Python script?

How do I select attributes and generate UTC time in the same querry? This doesn't work:

SELECT "beginposition","endposition","timeposition","datetime('now') as utc"
FROM Output

 


ebygomm
Influencer
Forum|alt.badge.img+32
  • Influencer
  • September 21, 2020
fikusas wrote:

This worked for some time, but stopped recently. Maybe it is possible convert local time (with Daylight savings adjusted) to UTC via Python script?

SELECT "beginposition","endposition","timeposition",datetime('now'as utc
FROM Output

Remove the double quotes from the datetime('now') part


fikusas
Contributor
Forum|alt.badge.img+5
  • Author
  • Contributor
  • September 21, 2020
fikusas wrote:

This worked for some time, but stopped recently. Maybe it is possible convert local time (with Daylight savings adjusted) to UTC via Python script?

It works! Thank you.


takashi
Influencer
  • September 21, 2020
fikusas wrote:

This worked for some time, but stopped recently. Maybe it is possible convert local time (with Daylight savings adjusted) to UTC via Python script?

 

If "beginposition", "endposition" and "timeposition" are attributes contained by input features, try this query.

SELECT *, datetime('now'as utc
FROM Output

 


Reply


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