Question
· 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
Discussion (4)1
Log in or sign up to continue

Lionel,

Check out the following article:

https://community.intersystems.com/post/handling-date-and-time-operations-cach%C3%A9

You might want to try something like:

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

%SYS>zw time
time="66014,35176"

%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,

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

https://docs.intersystems.com/latest/csp/docbook/DocBook.UI.Page.cls?KEY...

Best regards,
Kurro