Quote:
Originally Posted by ownedbycats
Question: I have a stored template, colours_daysbetween(), formatted as colours_daysbetween($#lastread, '#00aaff', '#69cfff', '#9bdeff').
Code:
program:
arguments(date, colourA, colourB, colourC);
now = format_date(today(), 'yyyy-MM-dd');
if days_between(now,date) <#1 then colourA
elif days_between(now,date) <=# 14 then colourB
elif days_between(now,date) <=# 30 then colourC
fi
I don't remember where I got this (I possibly wrote it myself) but is there any particular reason to use a format_date() instead of just 'today()'? The template works when tested with the latter.
|
Using format_date() ensures that the hours, minutes, and seconds are removed from the date, setting it to midnight. That makes the days_between() calculation more predictable in the face of differing times of day. That might not be important here, in which case using today() directly will be be faster.