Hi all,


I have a query regarding time datatype.

I  want to add two variables with time datatype of the format hh:mm:ss, and get the sum of two time variables.

Is there any way to do this?



Thanks in advance :)

Hi, dude.

I think that the best way is using a string split on the first variable and then sum the values one by one with the built-in-function add days, minutes, etc.

Solution

I see two ways.


Working in datetime

you have functions to add hours, minutes and seconds. You just need to use all three.

AddSeconds(AddMinutes(AddHours(Date1,Hour(Date2)),Minute(Date2)),Second(Date2)))

Disadvantages: 25 hours will look like 1 day and 1 hour. You need to transform that bit.


Working in time

You have NewDate. If you build it piece by piece you get the time you want.

NewDate(Hour(Date1)+Hour(Date2),Minute(Date1)+Minute(Date2),Second(Date1)+Second(Date2))


Which one do you prefer?

Solution

Nuno Reis wrote:

I see two ways.


Working in datetime

you have functions to add hours, minutes and seconds. You just need to use all three.

AddSeconds(AddMinutes(AddHours(Date1,Hour(Date2)),Minute(Date2)),Second(Date2)))

Disadvantages: 25 hours will look like 1 day and 1 hour. You need to transform that bit.


Working in time

You have NewDate. If you build it piece by piece you get the time you want.

NewDate(Hour(Date1)+Hour(Date2),Minute(Date1)+Minute(Date2),Second(Date1)+Second(Date2))


Which one do you prefer?

Thanks Nuno, the second worked for me :)