Round date and time

Hi,

is it possible to round a date/time to a nearest interval

say for example the input would be

21/4/2023 09:07:00 , and the out put would be 21/4/2023 09:00:00

also can it be done for half hours as well ,so input would be

21/4/2023 09:37:00 , and the output would be 21/4/2023 09:30:00

what i am trying to do is produce a dynamic time table as such (off course with the necessary parsing)

09:00:00 <<now>>
09:30:00 <<now>> add[ 30 minutes] round[]
10:00:00 <<now>> add [60 minutes] round[]
10:30:00 <<now>> add [90 minutes] round[]
11:00:00 <<now>> add [120 minutes[ round[]

hope this makes sense and thanks in advance

edit : sorry forgot to add that the round operator obviously didnt do the trick hence the post:)

Hi @paulgilbert2000

It should be possible with a bit of math. The idea is to extract the minutes value from the time, then divide by 30, then trunc, then multiply by 30.

<$let rounded={{{ [<now mm>divide[30]trunc[]multiply[30]pad[2]addprefix<now YYYY0MM0DD0hh>addsuffix<now 0ssXXX>] }}}>
...
</$let>

Fred

1 Like

Thanks a lot fred ,works prefect :grinning: