'2019-07-17T00:00:00.000000000Z' does not match format '%Y-%m-%dT%H:%M:%S.%fZ'
It is a problem you can find out by yourselves simply by adjusting the date and format:
Fail:
d = datetime.strptime("2019-07-17T00:00:00.000000000Z", "%Y-%m-%dT%H:%M:%S.%fZ")
Success:
d = datetime.strptime("2019-07-17T00:00:00", "%Y-%m-%dT%H:%M:%S")
Which means the problem comes from the %fZ
part.
From Python document, %f
means microsecond which means 6 digits.
d = datetime.strptime("2019-07-17T00:00:00.000000Z", "%Y-%m-%dT%H:%M:%S.%fZ")
That's the above will work
Edit: There are two choices you can have:
If the incoming string always ends with 3 zeros for the nanosecond part, you can adjust your format to
"%Y-%m-%dT%H:%M:%S.%f000Z"
If you are not sure, then you can just trim off last 3 digits from the input string
One way you can do:
input_string = "2019-07-17T00:00:00.000000000Z"
result = datetime.strptime(input_string[:-4], "%Y-%m-%dT%H:%M:%S.%f")
Here I excluded the last 4 characters (000Z
) from the string and the format is updated accordingly to remove the matching of last Z
.
time data does not match format '%y-%m-%d'
Use Y
for match YYYY
format, because y
is for YY
format of year:
self.train_date = datetime.datetime.strptime(train_date,'%Y-%m-%d').date()
ValueError: time data '02/03/2022' does not match format '%d/%m/%y '
To point out the year you need to use %Y
and also there is an additional space at the end of the format you gave that it's not present in the date. Try with date = datetime.strptime(date, '%d/%m/%Y')
Related Topics
Replace Only Exactly Matching String Python Ndarry
Read Merged Cells in Excel With Python
Flask Installed, But Modulenotfounderror: No Module Named 'Flask'
Stuck With Loops in Python - Only Returning First Value
Visual Studio Code Intellisense Is Very Slow - Is There Anything I Can Do
Auto Reloading Python Flask App Upon Code Changes
Heroku: No Default Language Could Be Detected for This App
How to Get a Random Value from Dictionary
Why Does It Say That Module Pygame Has No Init Member
Django: Get Current User in Model Save
How to Calculate R-Squared Using Python and Numpy
Split String At Nth Occurrence of a Given Character
Python3: Typeerror: List Indices Must Be Integers or Slices, Not Str
In Python, How to Find the Vowels in a Word
Most Efficient Way to Construct Similarity Matrix
Collecting and Reporting Pytest Results
How to Get Rid of the B-Prefix in a String in Python
Open() Gives Filenotfounderror/Ioerror: Errno 2 No Such File or Directory