Search code examples
pythonstrptime

time data in byte not matching format


last_appended_row_timestamp = datetime.strptime(str(last_appended_row_timestamp), "%Y-%m-%d %H:%M:%S")

The code here yields an error saying,

ValueError: time data "b'2019-12-08 23:59:59'" does not match format '%Y-%m-%d %H:%M:%S'.

b'2019-12-08 23:59:59' is byte, and putting the byte in str(), I got the result. What is the problem?? Thanks much in advance.


Solution

  • Because:

    str(b'2')
    >>> "b'2'"
    

    So you need change your code, like this:

    datetime.strptime(last_appended_row_timestamp.decode('u8'), "%Y-%m-%d %H:%M:%S")