Skip to main content
Question

Unable to convert time duration


will_catterick
Participant
Forum|alt.badge.img

Hi all! First post here, so I’m excited to get some feedback!

For context, I do a report on our organization’s EV chargers every month. In this report, I need to calculate the average time of day people are charging, the average charge time (duration), and the total duration.

Currently, I am unable to get the average duration and the total duration.

Here’s my process

  1. Convert the time to FME format using a DateTimeConverter
  2. Sum and average the times using a SatisticsCaclulator
  3. I attempt to convert the summary back into H:MM...

But then I am met with the below error:
 

Where am I going wrong?

4 replies

crutledge
Influencer
Forum|alt.badge.img+33
  • Influencer
  • July 3, 2025

Hi ​@will_catterick 

The date/time you have defined looks a bit off. The formula %k:%M format is looking for 2 digit hour and a 2 digit hour. 14:77 then the rest is undefined. This will probably not work but try adding in seconds to look for. 2 digit second with decimal

%k:%M:%S

That might complete without errors but give you weird numbers.

Hope that helps!


hkingsbury
Celebrity
Forum|alt.badge.img+55
  • Celebrity
  • July 3, 2025

When dealing with times like this (and credit to ​@todd_davis for sharing this) I find it so much easier to convert to epoch. and work with seconds. Then you’re not having to worry about overflowing minutes to hours, hours to days etc. At the end, you can convert it all back from epoch to standard time


stadimarmiladi
Contributor
Forum|alt.badge.img+8

Hey ​@will_catterick 

It might be worth checking out this post here: min, max and median time | Community It appears that the StatisticsCalculator is working fine for minimum and maximum times, however, the calculation of averages and durations is a bit more complex. 

Hope that’ll help 


takashi
Evangelist
  • July 4, 2025

Hi ​@will_catterick ,

I think the direct reason for this error is the format of the input value14773.33... did not match the specified date/time format - standard FME date/time format.

I assume that you can retrieve start datetime and end datetime for each charging from the source dataset and format them into the standard FME datetme format - %y%m%d%H%M%S.

If so, I would recommend you to perform all the calculations in seconds.

That is, calculate duration (from start datetime to end datetime) for each charging in seconds with DateTimeCalculater (Mode: Calculate Interval between Datetimes, Result Type: Seconds), and calculate sum and average of the durations too in seconds with StatisticsCalculator.

You can then calculate hours and minutes for the result values with these expressions, and concatenate them to make your required text - hours:minutes.

hours = @floor(seconds/3600)
minutes = @round(seconds) % 60 ← This expression is wrong. See the correction below.

The reason for not using DateTimeConverter here is, I thought that the total of charging durations a month could be 24+ hours. The time format %k:%M cannot describe 24+ hours.

 

[Correstion] Sorry, the expression for calculating minutes was wrong. Replace with this.

minutes = @floor((seconds - hours * 3600)/60)     [round down]

or

minutes = @round((seconds - hours * 3600)/60)     [nearest]


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