View Single Post
Old 11-03-2024, 05:27 AM   #748
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 12,482
Karma: 8025704
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by ownedbycats View Post
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.
chaley is offline   Reply With Quote