I have a text field where the user will be inputting the date in the form DD/MM/YYYY. I need a case to trigger only when that date is within 2 months of todays date. Any ideas on how I can do this?
Thanks in advance!
I have a text field where the user will be inputting the date in the form DD/MM/YYYY. I need a case to trigger only when that date is within 2 months of todays date. Any ideas on how I can do this?
Thanks in advance!
Hi!
If you are in a country where days precede months, e.g., DD/MM/YYYY, you first have to reorder that string to be MM/DD/YYYY, which is a real pain without arrays or regular expressions. This will do it, assuming the variable “d” contains the original date (in DD/MM/YYYY format), and “ms” is the variable that will end up with milliseconds of that original date. (If anyone knows an easier way to get the month portion…)
set (variable) ms to [[d.substring(d.indexOf('/') + 1, d.lastIndexOf('/')) ]]
set (variable) ms to [[ms]]/[[ d.substring(0,d.indexOf('/')) ]]
set (variable) ms to [[ms]]/[[ d.substring(d.lastIndexOf('/') + 1, d.length) ]]
set (variable) ms to [[Date.parse(ms) ]]
[Edit]. I did indeed find an easier way to get the middle portion (between the slashes). I updated the first expression above.
[Edit] It occurs to me that you can do this with a single, preposterous expression rather than four:
set ms to [[ Date.parse(d.substring(d.indexOf('/') + 1, d.lastIndexOf('/')).concat('/').concat(d.substring(0,d.indexOf('/'))).concat('/').concat(d.substring(d.lastIndexOf('/') + 1, d.length))) ]]