Question
Warren Oyco · Jun 13

Comparing Dates

Hi,

Any suggestion on how to compare dates? Below is my code but it does not seem to work.

USER>w $zdate(zdateh(x,8),1) > $zdate($zdateh(y,8),1)

When I set x to "06/01/2022" and set y to "04/01/2022" gives me an output of 1

When I set x to "09/01/2019" and set y to "04/1/2022" still gives me an output of 1

Any help is appreciated.

Thanks!

Product version: IRIS 2020.2
$ZV: HealthShare 2020.2 [HealthShare Modules: Core:20.1.8624 + Patient Index:20.0.8624] - IRIS for UNIX (IBM AIX for System Power System-64) 2020.1 (Build 217_1_20418U) Mon Dec 21 2020 12:09:33 EST
0
0 134
Discussion (7)1
Log in or sign up to continue

Hi.

Just compare 
w zdateh(x,8) > $zdateh(y,8)

Regards,
Matjaž

What happens if you try this?

w $zdateh(x,1) > $zdateh(y,1)

This worked as well! Thank you for your input!

Which format do you use - DD/MM/YYYY?

Be carefull : the second parameter of $zdateh is =1 for US format (mm/dd/yyyy), =4 for European format (dd/mm/yyyy) and =8 for yyyymmdd format.
Luckily, $zdateh is smart enough to know your date is really US and not yyymmdd, but the correct answer is to use $zdateh(x,1) > $zdateh(y,1), and not 8 as second parameter :

write $zdateh("05/01/2022",1)
66230  -> the internal date for may 1st 2022
write $zdateh("05/01/2022",4)
66114  -> the internal date for 5 january 2022
write $zdateh("05/01/2022",8)
66230  -> $zdateh expects yyyymmdd, assumes this is US format (but this is wrong if European format was intended)

Gotcha! that's really helpful. Appreciate the input. Thank you!