Unfortunately, you cannot pass 0 because there is no month 0 , so you get ValueError: month must be in 1..12 , you cannot miss a month or day, because both of them are necessary.
If you do not know the exact year or month, just go to 1 month and day, and then save only part of the year.
>>> d = datetime.date(year=1940, month=1, day=1) >>> d datetime.date(1940, 1, 1) >>> d.year 1940 >>> d = datetime.date(year=1940, month=1, day=1).year >>> d 1940
The second statement is an abbreviation for the first.
However, if you just want to keep the year, you do not need a datetime object. You can save the integer value separately. A date object implies a month and a day.
source share