This is what first came to my mind:
select date (date '0000-12-31' + interval '733973 days');
>> "2010-07-20"
or
select date (date '0000-12-31' + interval '1 days' * 733973);
>> "2010-07-20"
It simply adds the number of days to the date 0000-12-31
. It doesn't use the date 0001-01-01
, as datetime.toordinal()
is defined to be 1
for this date, hence the -1 offset.
From the python docs
date.fromordinal(ordinal)
Return the date corresponding to the proleptic Gregorian ordinal, where
January 1 of year 1 has ordinal 1...
Edit:
If the date 0000-31-12
is not recognised as a valid date, you can easily change the statement to something like:
select date (date '0001-01-01' + interval '733973 days' - interval '1 day');
or
select date (date '0001-01-01' + (interval '1 days' * (733973 - 1)));