Say I have two horologs or timestamps, how can I compare them? I know that just time1 > time2 doesn't work because it will compare them as strings which is not correct.
To find way how to compare time, you should remember format for $horolog, which is has two parts separated with comma. First of part it is a date, which is actually numbers of days since 1841 year, so $horolog=1 it is 01/01/1841. Next part is a seconds in a day, no more than 86400, and may have milliseconds after point.
Know it, you can easily convert $horolog to seconds and compare them
it depends what format your date-time is currently in but I just find it hard work to start messing about with $piece etc, I use the FOLLOWS command " ] "
To find way how to compare time, you should remember format for $horolog, which is has two parts separated with comma. First of part it is a date, which is actually numbers of days since 1841 year, so $horolog=1 it is 01/01/1841. Next part is a seconds in a day, no more than 86400, and may have milliseconds after point.
Know it, you can easily convert $horolog to seconds and compare them
You can also use SQL function DATEDIFF, to see difference in seconds between to dates
Thanks, the first option seems to be what I need
it depends what format your date-time is currently in but I just find it hard work to start messing about with $piece etc, I use the FOLLOWS command " ] "
it works in external format as well
kevin
very interesting solution
FOLLOWS gives wrong result in some cases:
If you do not care about fractions of seconds, convert the $H values to count of seconds .. $zdt(datetime,-2) .. and then compare the integers:
set date1 = $zdth("2016-01-02 00:15",3)
set date2 = $zdth("2016-01-02 01:00",3)
zw date1,date2
w $zdt(date1,-2)>$zdt(date2,-2)
If you do care about the seconds fractions you can use the follows operator with some of the external formats:
s d1=$zts h .001 s d2=$zts
zw d1,d2
d1="64180,33196.069"
d2="64180,33196.07"
w $zdt(d1,3,1,6)]$zdt(d2,3,1,6)
0
w $zdt(d2,3,1,6)]$zdt(d1,3,1,6)
1
/// note: comparing the count of seconds would consider the d1 and d2 equal.
Social networks
InterSystems resources
Log in or sign up
Log in or create a new account to continue
Log in or sign up
Log in or create a new account to continue
Log in or sign up
Log in or create a new account to continue