Compare dates in a Case statement

Cybertrack,

You can rearrange the input string from dd/mm/yyyy to yyyy.mm.dd so it plays nice with the date.parse() function. I’ve attached another copy of my example with a new page that demonstrates two paths you could take.


It will be a bit easier if you separate each date component into different text fields. If you set the day to LVAR1, month to LVAR2, and year to LVAR3, then you can set a variable (or set text) to:

[[LVAR3]].[[LVAR2]].[[LVAR1]] to rearrange it to yyyy.mm.dd, which you can then parse. You are basically just combining three strings.

If you want to use just one Text Field, you can rearrange it using the substring(x, y) function which will return the characters from x to y. Using a local variable set to the input Text Field, you could use the following function to rearrange the date:

[[LVAR1.substring(6,10)]].[[LVAR1.substring(3,5)]].[[LVAR1.substring(0,2)]]

So [[LVAR1.substring(6,10)]] would return characters from (but not including) the 6th to the 10th character–characters 7 through 10–i.e. the year.

Then you can use the [[Date.Parse()]] function to compare your dates. Just so you know, date.parse() converts the date string into the milliseconds elapsed since January 1, 1970, 00:00:00 UTC.

I also wanted to call you attention to the addyears() function which you can use to add or subtract 21 years for your comparison. So once my date is arranged in the yyyy.mm.dd format, you can add or subtract years using the following function:

[[LVAR1.addYears(21)]]

Where LVAR1 is the rearranged date input.

I hope that makes sense. See the file!
DateCompare.rp (72.7 KB)