Skip to main content

Hi, this must be easy but can't seem to find it...

I want to convert duration from seconds to hours, minutes, seconds. So 337759 seconds should be 93h49m19s.

I thought the DateTimeConverter should help me, but can't seem to get it right:

results in 21h49m19s...

I could calculate it myself, but I guess I'm overlooking a setting in this transformer?

Don't think you can use the dates like that. Everything is 24 hour. If the seconds go over 31 days, you'll need to change the 1st DateTimeConverter to %j to account for months.

 

Here's a simple workaround that should work.

 

 

Attached .fmwt


I think these three math operations and one string concatenation could always generate required value, even if the duration was greater than 31 days (=2,678,400 seconds). Assuming that an attribute called "duration" stores the original duration value in seconds, like 337759, 3000000 etc.

h = @int(@Value(duration)/3600)
m = @int((@Value(duration)-@Value(h)*3600)/60)
s = @Value(duration)%60
hms = @Value(h):@Value(m):@Value(s)

Setting example with an AttributeCreator

0684Q00000ArLLNQA3.png


I think these three math operations and one string concatenation could always generate required value, even if the duration was greater than 31 days (=2,678,400 seconds). Assuming that an attribute called "duration" stores the original duration value in seconds, like 337759, 3000000 etc.

h = @int(@Value(duration)/3600)
m = @int((@Value(duration)-@Value(h)*3600)/60)
s = @Value(duration)%60
hms = @Value(h):@Value(m):@Value(s)

Setting example with an AttributeCreator

0684Q00000ArLLNQA3.png

thank you @jlbaker2779 and @takashi for your suggestions, I agree it's easy to calculate yourself but still feels a bit cumbersome, especially if you want to do it for several attributes at once...

So I think it's worth a new idea to make this possible in the DateTimeConverter

https://knowledge.safe.com/idea/115166/datetimeconverter-add-up-more-than-24hours.html? 

I had this similar but needlessly more complicated workaround :

0684Q00000ArMdeQAF.png


Yeah that should be easier to calculate! I agree with you!


Reply