Add to time ( time ; hours ; minutes ; seconds ) -> Result

As we have the command: Add to date ( date; years; mounths; days) -> Result

Could we have the same for time ?
Add to time ( time ; hours ; minutes ; seconds ) -> Result

Now, you have to remenber to use % to convert using 24Hrs.


Time in 4D is NOT the time of day (moment of time), it is the duration of time.

Of course you can modulo it to represent the time of day, but by default, it is correct behaviour to overflow 24 hours, or go negative for that matter.

As Keisuke wrote, Time is number of seconds, starting with 00:00:01.

It allows to count difference in seconds between two times, represented as time display.

You can test this by example like this:

Code 4d

Another example for “Time is difference, not absolute time” is:

$string1:=String(Current date;ISO date GMT;Current time)
$string2:=String(Current date;ISO date;Current time)

$t1:=Time(substring($string1;1;length($string1)-1))  // remove Z from time

ALERT(String($t1-$t2))  // local time zone offset, including daylight saving for today
Code 4d

Thanks for your answers.
This feature request is for add time.

For example. I have a process that i want to execute each 2 hours. And I want to show for the user next time it will do.

So I have to do: $ProxTime:=current time+?02:00:00?

But, if the current time = ?23:15:05? and does current time+?02:00:00?

I will get : $ProxTime = ?25:15:01?

What I want with the “add time” is to obtain the same as %?24:00:00? allways respect the 24 hrs.
Of course, I will have to take in account the day (+1) in the case I need also the day.

Hi Alfonso,
I always use timeStamps in these situations (and many more). You’ll need 3 or 4 routines for that, nothing more. Some code examples:

You have to consider daylight saving time as well

Thanks Arnuad.
Thanks for the example.
We have our own system for this.
The idea will be, if possible, simplify the way to do.

It can get super complicated.

1 Like

There’s a “rule” that I always respect when working with time in computers: nothing but UTC. Then daylight savings time, jet lag and so on is just a matter of UI. For example:
timeStampToText(timeStampValue) -> UTC day + hour string
timeStampToText(timeStampValue;True) -> converted to local day + hour string

1 Like

I’m just looking for a command that take in account the time in 24 hrs. limit.
So, if I add 1 hr. to the current time ,regardless the day, I allways will get it with 24 hr. result.

If current time is ?23:55:00?
$ProxTime:=current time+?01:00:00? -> ?24:55:00?
Now I have to remember to do : $ProxTime:=$ProxTime%?24:00:00? - > ?00:55:00?

What i’m looking for:

$ProxTime:=Add to time(current time;1;0;0)
$ProxTime - > ?00:55:00?

Timestamps routines must be able to extract separately from a timestamp:

  • the day ( c_date($0) )
  • the hour ( c_hour($0) )
    If I don’t want to display the day, the second one would be my choice. But from ?25:00:00?, the fact remains, it is tomorrow (*). It’s just a choice of interface to hide it.

(*) mañana por la mañana :thinking:

1 Like