Skip to main content
Solved

Rounding time to 5 minute intervals

  • June 28, 2016
  • 9 replies
  • 150 views

Forum|alt.badge.img

Hi

I have a file with the following layout:

N19111N,,287026.00,407599.00,2016-02-01 06:58:33,25.0,0.0,0.4

 

N19111N,,287026.00,407599.00,2016-02-01 07:03:33,25.0,1.0,25.0

 

N19111N,,287026.00,407599.00,2016-02-01 07:08:33,27.0,1.0,27.0

 

N19111N,,287026.00,407599.00,2016-02-01 07:13:33,28.0,3.0,9.4

 

N19111N,,287026.00,407599.00,2016-02-01 07:18:33,24.0,1.0,24.0

Is there an easy expression to round down to the previous 5 minute intervals like so:

N19111N,,287026.00,407599.00,2016-02-01 06:55:00,25.0,0.0,0.4

 

N19111N,,287026.00,407599.00,2016-02-01 07:00:00,25.0,1.0,25.0

 

N19111N,,287026.00,407599.00,2016-02-01 07:05:00,27.0,1.0,27.0

 

N19111N,,287026.00,407599.00,2016-02-01 07:10:00,28.0,3.0,9.4

 

N19111N,,287026.00,407599.00,2016-02-01 07:15:00,24.0,1.0,24.0

Thanks

Best answer by takashi

Hi @aburns, how about this?

  1. DateFormatter (1): Convert the datetime string to the number of seconds elapsed from the epoch  (Destination Date Format: %s).
  2. ExpressionEvaluator or AttributeCreator: Divide the value by 300 seconds (= 5 minutes), truncate decimal places, and multiply by 300.
  3. DateFormatter (2): Restore the original datetime format (%Y-%m-%d %H:%M:%S).

Assuming that the time value converted by the first DateFormatter is stored by an attribute called 'time', the expression is:

@int(@Value(time)/300)*300
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.

9 replies

takashi
Celebrity
  • Best Answer
  • June 28, 2016

Hi @aburns, how about this?

  1. DateFormatter (1): Convert the datetime string to the number of seconds elapsed from the epoch  (Destination Date Format: %s).
  2. ExpressionEvaluator or AttributeCreator: Divide the value by 300 seconds (= 5 minutes), truncate decimal places, and multiply by 300.
  3. DateFormatter (2): Restore the original datetime format (%Y-%m-%d %H:%M:%S).

Assuming that the time value converted by the first DateFormatter is stored by an attribute called 'time', the expression is:

@int(@Value(time)/300)*300

david_r
Celebrity
  • June 28, 2016

Here's one possible solution using string manipulation and lists:


david_r
Celebrity
  • June 28, 2016

Hi @aburns, how about this?

  1. DateFormatter (1): Convert the datetime string to the number of seconds elapsed from the epoch  (Destination Date Format: %s).
  2. ExpressionEvaluator or AttributeCreator: Divide the value by 300 seconds (= 5 minutes), truncate decimal places, and multiply by 300.
  3. DateFormatter (2): Restore the original datetime format (%Y-%m-%d %H:%M:%S).

Assuming that the time value converted by the first DateFormatter is stored by an attribute called 'time', the expression is:

@int(@Value(time)/300)*300

Always fun to see how differently you can do things in FME and still get the same results :-)


takashi
Celebrity
  • June 28, 2016

Always fun to see how differently you can do things in FME and still get the same results :-)

Yeees, me too :-) There is more than one way almost always. The StringReplacer can be used to replace the last four characters appropriately.

  • Text To Match: (....)$
  • Replacement Text: <0:00 or 5:00 according to the number of fourth from last>
  • Use Regular Expressions: yes

Forum|alt.badge.img
  • Author
  • June 28, 2016

Hi

Thanks for the replies. I am still experiencing issue:

Any ideas where im going wrong?

Thanks


david_r
Celebrity
  • June 28, 2016

Hi

Thanks for the replies. I am still experiencing issue:

Any ideas where im going wrong?

Thanks

Maybe try setting source date format to "%s" in the last DateFormatter? FME is not very good at guessing date formats, in my experience...


takashi
Celebrity
  • June 28, 2016

Hi

Thanks for the replies. I am still experiencing issue:

Any ideas where im going wrong?

Thanks

@aburns, you have to specify the Source Date Format parameter in the second DateFormatter. Try setting '%s' there. See also the help doc on the DateFormatter to learn more about date/time formats


Forum|alt.badge.img
  • Author
  • June 28, 2016

@takashi, @david_r

Spot on, missed that! Sorted that out nicely!

thanks both, appreciated all the replied as we can all see we can get to the same endpoint using different method. I didnt even think of the string replacer and regex.

Regards

Andy

 


Forum|alt.badge.img
  • Author
  • June 28, 2016

Hi @aburns, how about this?

  1. DateFormatter (1): Convert the datetime string to the number of seconds elapsed from the epoch  (Destination Date Format: %s).
  2. ExpressionEvaluator or AttributeCreator: Divide the value by 300 seconds (= 5 minutes), truncate decimal places, and multiply by 300.
  3. DateFormatter (2): Restore the original datetime format (%Y-%m-%d %H:%M:%S).

Assuming that the time value converted by the first DateFormatter is stored by an attribute called 'time', the expression is:

@int(@Value(time)/300)*300

This works nicely and very easy.