58
Views
16
Comments
Adding time in dd:hh:mm:ss format

Hello everyone,

I’m facing a issue and i need help

I have var called timer  (time datatype)

It should calculate difference between two times and save the result 


I  want to add the  this timer variable with the difference between start time and the end time


Timer + (endtime-starttime)

Timer : 23:30:00 saved in db

Start time : 1:00:00

End time: 12:00:00

It’s gonna be 34 hours and 30 min 

I need like 

1 day 10 hours 30 min 


I have tried this function:

AddSeconds(timer(starttime-endtime)


Disadvantages: more than 24 hours will count as zero and start again from 00:00:00 


I need function that  count timee in 

(dd:hh:mm:ss)

2024-03-22 09-17-23
Chandra Vikas Sharma

Hi,

Please refer below post for your Query,

https://www.outsystems.com/forums/discussion/56669/add-timehhmmss/

Thanks

CV

UserImage.jpg
Jumanah Aldulaim

Thank you but the solutions not match with my issue i need it in (dd:hh:mm:ss)

Based on time data type so if the timer more than 24 hours consider as a day  


2021-09-06 15-09-53
Dorine Boudry
 
MVP

Hi @Jumanah Aldulaim ,

you say that your variable is a time, that by definition doesn't know about days.  Use a DateTime instead.

For a how to, see @Siya reply.

UserImage.jpg
Jumanah Aldulaim

Thank you for your repay but i need to calculate based on time not in datetime , i need to sum time if more that 24 hours consider it as a day and continue count … like 2 day 12 hours 30 minutes.. and so on 

2021-09-06 15-09-53
Dorine Boudry
 
MVP

There is simply no place for days in a time variable.

If you object to the datetime format, you could just store it as integer (i.e. number of seconds)  that's for storage / counting.

As for display, write a small client function converting seconds into the string representation you need.  

But seriously, DateTime will work just fine.

2019-01-07 16-04-16
Siya
 
MVP

Believe this for just rendering on the screen.  Attached an implementation of the same.

  1. Create a new DateTime using the Timer (  Year, Month & Day will be 1900, 01, 01 )
  2. Calculate the difference in seconds  between Start & End Time ( DiffSeconds is used where DateTimes are created as in Step 1 )
  3. Now add the difference to Date time created in Step 1
  4. Finally create a formatted string with difference between Null date and Date time created in Step 3. 


TimeDemo.oml
UserImage.jpg
Jumanah Aldulaim

Thank you i will try it

2024-10-12 12-11-20
Kerollos Adel
Champion

check this 

TimeCalculation.oml
UserImage.jpg
Jumanah Aldulaim

Still not match with my issue 


I need to get the days based  on the the adding saved timer with the difference between  two (time  attributes)

AddSeconds(timer(starttime-endtime) >24 hours? 

Consider it as one day then continue check again 

Ex: 1 day 23 hours 50 minutes 20 second 

AddSeconds(timer(starttime-endtime)> 24 hours 

Consider it as two days then continue check again;,,

Because if i use this function AddSeconds(timer(starttime-endtime) it doesn’t calculate  days 

How? 

2020-09-15 13-07-23
Kilian Hekhuis
 
MVP

Hi Jumanah,

You are mixing up data storage and representation. The best thing you can do is store the difference as a number of seconds (in an Integer), and convert that to a dd:hh:mm:ss representation using an action that calculates the various components, and returns those, so you display it on screen (or an action that builds the entire dd:hh:mm:ss Text).

UserImage.jpg
Jumanah Aldulaim

i did and it works thank you ,but is it good for data storage ? because the number in seconds is huge number  imagine we had 40 hours ..

2020-09-15 13-07-23
Kilian Hekhuis
 
MVP

Hi Jumanah,

If you use an Integer, you can represent 2,147,483,647 seconds, which is about 68 years. If you want to go further, use a Long Integer. This will give you enough seconds to represent more years than the age of the universe :).

(40 hours is just 144,000 seconds, which is a relatively small number)

2020-09-15 13-07-23
Kilian Hekhuis
 
MVP

You're welcome. Don't forget the answers that helped you as Solution, thanks!

UserImage.jpg
Jumanah Aldulaim

these are the function i used to get days,hours,mintues and seconds based on number of seconds

2020-09-15 13-07-23
Kilian Hekhuis
 
MVP

At a first glance that seems to work, though it's easily testable :).

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.