Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ValueError: time data '0000-00-00 00:00:00' does not match format '%Y-%m-%d %H:%M:%S'

I am trying to convert my WordPress site to a static site generator using the program exitwp. But during the conversion process, I always get the following error message:

Traceback (most recent call last):
  File "exitwp.py", line 374, in <module>
    write_jekyll(data, target_format)
  File "exitwp.py", line 296, in write_jekyll
     i['date'], '%Y-%m-%d %H:%M:%S').replace(tzinfo=UTC()),
   File "/Users/xxxxx/.pyenv/versions/2.7.10/lib/python2.7/_strptime.py", line 325, in _strptime
(data_string, format))
ValueError: time data '0000-00-00 00:00:00' does not match format '%Y-%m-%d %H:%M:%S'

I am not a Python programmer but I looked up what the time data format means and it seems to me that '0000-00-00 00:00:00' DOES MATCH the format '%Y-%m-%d %H:%M:%S'.

Any idea what is wrong? Help would be very appreciated!

like image 551
petzi Avatar asked Dec 23 '22 14:12

petzi


1 Answers

%Y matches years in the range 0001 through to 9999, see the table in the module documentation:

%Y
Year with century as a decimal number.
0001, 0002, …, 2013, 2014, …, 9998, 9999

Your year 0000 falls outside of that range.

The same issue applies to %m and %d (the acceptable ranges are 01 through to 12, and 01 through to 31, respectively).

That's because datetime.datetime() objects have the same range for their attribute values, there is no datetime.datetime(0, 0, 0, 0, 0) object. datetime.datetime.min is set to datetime.datetime(1, 1, 1, 0, 0) (so 0001-01-01 00:00:00).

Presumably 0000-00-00 00:00:00 means 'no date available'; you'll have to alter the input to replace those dates, or handle that value to replace it with something else (perhaps None would be acceptable?)

like image 79
Martijn Pieters Avatar answered Apr 09 '23 06:04

Martijn Pieters