0
select date '0-1-1';

2000-01-01

Year 0 doesn't exist according to Wikipedia, so shouldn't Postgresql give an error instead of jumping to 2000?

Year zero does not exist in the anno Domini system usually used to number years in the Gregorian calendar and in its predecessor, the Julian calendar. In this system, the year 1 BC is followed by AD 1

https://en.wikipedia.org/wiki/Year_zero


edit: Even though inputs like date 123-1-1 work as expected, somehow they made it so anything less than 100ad would require leading 0's to prevent this weird behavior, ex: date 0001-01-01. Given this information, I tried date 0000-01-01 and it does indeed give an error, specifically "22008 out of range".

2

Because that is how it was designed and implemented. See here

If BC was not specified, and if the year field was two digits in length, then adjust the year to four digits. If the field is less than 70, then add 2000, otherwise add 1900.

(although two digits should probably be "one or two")

People often use the last digits of a recent past or near future year to represent the year, dropping the 19 or the 20. This heuristic was designed to accommodate that raw fact.

That the year 0 doesn't exist has nothing to do with it. The years 1, 2, and 69 do exist, and yet the heuristic applies to that as well.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.