Working with dates in workflows
How does one due date comparisons where only the date should be considered? As an example, how can you check that a date is earlier than today? The only way I know of to get the current date is the 'now' function, but that includes a time, so comparisons don't work since the time isn't accounted for. For example, this:
if (due date < now)
doesn't work at all because any time except this instant will make this true. Meanwhile, techniques along these lines:
if (due date > now - 1 day)
won't work because anything after this time yesterday will pass. What I really need is something like this:
if (dateOnly(due date) < dateOnly(now))
I tried using format() to accomplish this, but the editor didn't like it. So what's the correct way to do this?
if (due date < now)
doesn't work at all because any time except this instant will make this true. Meanwhile, techniques along these lines:
if (due date > now - 1 day)
won't work because anything after this time yesterday will pass. What I really need is something like this:
if (dateOnly(due date) < dateOnly(now))
I tried using format() to accomplish this, but the editor didn't like it. So what's the correct way to do this?
Please sign in to leave a comment.
Please don't forgot complete date by 'yyyy-mm-dd'.
Having these values and using arithmetical operations you can define the only 'date' value without the 'time' addition.
I wasn't familiar with the millis method. Is it part of a larger family of related methods? (It isn't included in the new workflow documentation.)
rule test date when Priority.changed { var nowMillis = (now - 2011-08-26).millis; var dueDateMillis = (Due Date - 2011-08-26).millis; var secondsNow = (nowMillis - nowMillis % 1000) / 1000; var minutesNow = (secondsNow - secondsNow % 60) / 60; var hoursNow = (minutesNow - minutesNow % 60) / 60; var daysNow = (hoursNow - hoursNow % 24) / 24; minutesNow = minutesNow % 60; hoursNow = hoursNow % 24; var secondsDueDate = (nowMillis - nowMillis % 1000) / 1000; var minutesDueDate = (secondsDueDate - secondsDueDate % 60) / 60; var hoursDueDate = (minutesDueDate - minutesDueDate % 60) / 60; var daysDueDate = (hoursDueDate - hoursDueDate % 24) / 24; minutesDueDate = minutesDueDate % 60; hoursDueDate = hoursDueDate % 24; if (daysDueDate < daysNow) { <define statements> } }Thank you for pointing the absence of the 'millis' method in reference, I'll correct it.