I'm creating a Django app that needs to perform date differences. Given a model with a start_date and end_date, both DateFields, on Postgres this works as a command like:
model.objects.annotate(difference=F(end_date)-F(start_date))
will work perfectly fine. However, on an SQLite backend this doesn't work as well.
Rather than giving a timedelta (or similar), it returns a string, which is approximately the difference in years. However, SQLite has a command julianday() which converts the date to a "julian day" which can at least be used to get a difference in days.
For example, on the dbshell, this will give the right number of days difference:
SELECT julianday(end_date) - julianday(start_date) FROM 'appname'.'model';
Is there a way I can:
-
Check the database backend - eg. is SQLite or not?
-
and, then if it is SQLite wrap it in the
juliandayfunction?
Aucun commentaire:
Enregistrer un commentaire