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?
Comment actions Permalink
You can use date range millis value:
var nowMillis = (now - 2013-08-21).millis;
var dueDateMillis = (Due date - 2013-08-21).millis
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.
Comment actions Permalink
Thanks for the reply, but I'm afraid I need further assistance. Now, I'm sure I'm just missing something obvious here (I am working on about 30 minutes' sleep, after all), but I don't see how I can put together the building blocks I have to get what I need. As a very specific example, how do I check to see if the Due Date field is earlier than today? Here, I define "earlier" to mean that the date portion of the Due Date is less than the date portion of now(), irrespective of the time portion of either field.

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.)
Comment actions Permalink
'Earlier' by dates days can be evaluated by the following workflow:
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.

Please sign in to leave a comment.