Skip to main content
Solved

Seconds to h/m/s but more than 24h

  • June 6, 2020
  • 4 replies
  • 188 views

becchr
Influencer
Forum|alt.badge.img+32

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?

Best answer by jlbaker2779

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

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.

4 replies

Forum|alt.badge.img+2
  • Best Answer
  • June 6, 2020

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


takashi
Celebrity
  • June 7, 2020

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


becchr
Influencer
Forum|alt.badge.img+32
  • Author
  • Influencer
  • June 7, 2020

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


philippeb
Enthusiast
Forum|alt.badge.img+22
  • Enthusiast
  • October 2, 2024

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