Skip to main content

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

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

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


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 :-)


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

Hi

Thanks for the replies. I am still experiencing issue:

Any ideas where im going wrong?

Thanks


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...


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


@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

 


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.


Reply