View Single Post
Old 04-16-2022, 09:06 AM   #375
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,529
Karma: 8075744
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by ownedbycats View Post
Quick question: Is a days_between with the current date the only way to check "specified datetime column is more/less/equal to xx days ago" in a template?

If there isn't, I'll probably figure out a days_ago() stored template with variables for the column name and number of days.
It isn't the only way but it is the easiest way.

You can also do it with timestamps, using format_date(date, 'to_number') to get the timestamp. Get the timestamp for both dates and do the arithmetic. This lets you get down to differences of seconds. Example:
Code:
program:
	def seconds_between(d1, d2):
		t1 = format_date(d1, 'to_number');
		t2 = format_date(d2, 'to_number');
		return t1 - t2
	fed;

	def seconds_to_days(s):
		s / 86400
	fed;

	s = seconds_between(today(), '20220101');
	'seconds: ' & s & ', days; ' & seconds_to_days(s)
produces (today)
Code:
seconds: 9115307.01234293, days; 105.5012385687839
chaley is offline   Reply With Quote