Issue Working With Dates in Tracker

Original post:
Dear All,
I hope you are doing okay?
Please, I need some help with dates on an event program.
I am trying to create a validation on a date field to ensure that only dates entered within a specified period are allowed in that field e.g. ART start date must be between October 1, 2017 and September 30, 2018.
How do I create this using a Program rule?
I have tried things like:
V{dt_art_st}>=‘2017-10-01’ && V{dt_art_st}<=‘2018-09-30’
and
#{dt_art_st}>=‘2017-10-01’ && #{dt_art_st}<=‘2018-09-30’
and
#{dt_art_st}>=(“2017-10-01”) && #{dt_art_st}<=(“2018-09-30”)
Not sure what to do or how to proceed with this.
Thank you for your help

Hello All,
Been struggling a bit to get a date validation rule to work in tracker.
The post is above.

When this was not working the way I wanted, I tried to setup a check to see if the rule was working well using the d2:daysBetween function as per guidance (see below)

Here is the rule I wrote:
d2:daysBetween(#{dt_art_st}, ‘2018-09-30’)

This was the result:
image

On a hunch, I changed the date format from YYYY-MM-dd in the guidance to dd-MM-YYYY (as seen below):
d2:daysBetween(#{dt_art_st}, ‘30-09-2018’)
Cleared cache and tried again and this was the result
image

So, I am not sure whether this is an issue with the system or an issue with the documentation. However, even with these changes, the validation rule is still NOT working and does not recognize dates within the specified period.

Not sure what to do next with this.

Thanks for your help.

1 Like

Hi @ifeanyiokoye, tagging the @dhis2-tracker team to advise on this.

Best,
James.

1 Like

Thank you @jomutsani.

Will await the input from the @dhis2-tracker team.

1 Like

Hi @ifeanyiokoye,

Sorry for the late reply.

Thanks for finding the problem an reporting it. When the server is using the date format dd-MM-YYYY this doesn’t work as expected (as in your case). I’ve created a JIRA-issue to get this resolved.

I do have a workaround for you though. Something like this should do the trick:

!(d2:daysBetween(V{current_date}, '01-10-2017') <= d2:daysBetween(V{current_date}, #{dt_art_st}) && d2:daysBetween(V{current_date}, '30-09-2018') >= d2:daysBetween(V{current_date}, #{dt_art_st}))

This will trigger the program rule actions when the chosen dt_art_st is not in the range 01-10-2017 - 30-09-2018.

Hope this thelps.

1 Like

Thank you @Joakim

I will try this and get back to you.

Do you mind explaining the rationale behind the code.

Thank you.

1 Like