Relative Content

Tag Archive for djangopostgresql

Sorting a string before a number with Postgres and Django

I want to use fuzzy dates for sorting a Django query, so you can use a full date if you have it, but maybe you only know year and month or maybe you only know year or even decade. For example, Jan XX 2024 would come before Jan 1 2024 and Jan 2 2024. I was originally planning to store as a string 202401XX, 20240101, etc, but Postgres naturally sorts characters after numbers so this would put the date with no day AFTER the date with day specified.

Sorting a string before a number with Postgres and Django

I want to use fuzzy dates for sorting a Django query, so you can use a full date if you have it, but maybe you only know year and month or maybe you only know year or even decade. For example, Jan XX 2024 would come before Jan 1 2024 and Jan 2 2024. I was originally planning to store as a string 202401XX, 20240101, etc, but Postgres naturally sorts characters after numbers so this would put the date with no day AFTER the date with day specified.