strftime for datetime before 1900 year

Recently I’ve got an error for birthdays before 1900 year

ValueError: year=1890 is before 1900; the datetime strftime() methods require year >= 1900

for this code:

import datetime
datetime.date(1890,7,1).strftime('%d.%m.%Y')

And it’s described in the documentation

The full set of format codes supported varies across platforms, because Python calls the platform C library’s strftime() function, and platform variations are common. To see the full set of format codes supported on your platform, consult the strftime(3) documentation.
The exact range of years for which strftime() works also varies across platforms. Regardless of platform, years before 1900 cannot be used.

One of the ways to solve this:

birthday = datetime.date(1890,7,1)
'{0.day:02d}.{0.month:02d}.{0.year:4d}'.format(birthday)
comments powered by Disqus