Lionel Woods · Sep 28, 2021

How to change valid Date range to a valid Time range

I am trying to convert a valid date range (Previous Day - Current Day) to a valid date/time range (-15 mins from current date/time to current date/time) for a Task to run (Format needs to be YYYY-MM-DD hh:mm:ss)

Code being used currently for date range is 

set previousDay=$zdatetime($horolog-1,3)
set currentDay=$zdatetime($horolog-0,3)

Can anyone help?


Product version: HealthShare 2017.2
0 171
Discussion (4)1
Log in or sign up to continue

I don't know exactly what you mean, maybe you have a example for us?

Something like:

DateFrom: 2021-09-27  DateThru: 2021-09-28
Expected time range:  from ???? thru ????


Check out the following article:

You might want to try something like:

%SYS>s time=$PIECE($horolog,",",1)-1_","_$PIECE($horolog,",",2)

%SYS>zw time

%SYS>w $zdatetime(time,3)
2021-09-27 09:46:16

When you just do $horolog-1, you're truncating the time off of $horolog. $PIECE lets you modify and combine the date/time segments of $horolog independently.

Hi Lionel Woods

Please check below code:

set prevDay = $system.SQL.DATEADD("minute",-15,$system.SQL.DATEADD("hour",-24,$ZDATETIME($HOROLOG,1,1)))
set todayDay = $system.SQL.DATEADD("minute",-15,$ZDATETIME($HOROLOG,1,1))
w prevDay
w todayDay



The $HOROLOG is the cache datetime format, then the first part is de date and the second part is the time. The time is in seconds, then if you want to increase 15 minutes, you should to plus the time (15*60)

This is a example:

It only works if you are in the same day, because it raises an error

The best way to increase minutes, days, months, etc... is using $system.SQL.DATEADD method

Best regards,