Warning in Python about format date

In writting a Python script and I run base.query based on my own written query, when I run the script I get a warining [Warning] format date: Invalid isoformat string: ‘2023-05-01T00:00:00Z’
My original format is European (example 01/05/2023) because of this warning I have a problem than when I whan to see if a date (that is a result of using the function base._list_rows than return for an example 01/05/2023) is between dates from the query I dont get a right result because 01/05/2023 is not equal to ‘2023-05-01T00:00:00Z’. Is there a way that I can format ‘2023-05-01T00:00:00Z’ to be ‘2023-05-01’

Replace T by space and remove the Z at the end. Should look like this: YYYY-mm-dd HH:MM:SS

Do you have a example how to do that the query that is wrote is
Select ID, ProjectCode, DateFrom, DateTo, EngagmentMath, Biliable from S_EMPLOYEE_INVOLMENT…
the problematic colums are DateFrom and DateTo

In my table “Date” I can do a select like that. It is what you try to do?

The thing is when I get a result from SQL it is ok but when the Query in executed via Python script I get a result like this ‘2023-05-01T00:00:00Z’ and I want to convert it to 01/05/2023 because the date format in table is DD/MM/YYYY

I see. I usually use pypi datetime modules.

from datetime import datetime
from dateutil.parser import parse

dateVal = parse(VALUE_FROM_DB)
print(dateVal.strftime('%Y-%m-%d'))

It works, thank you!

1 Like

Please tell me how you solved this problem?
My code doesn’t want to work with the European format

from datetime import datetime
from dateutil.parser import parse

date Val = parse('SELECT `Event start` FROM `Collegium` ')
print(dateVal.strftime('%d.%m.%Y %H:%M'))
  1. SELECT Event start FROM Collegium is not a date value.
  2. date Val has to be one word
  3. You should read the manual on how to use queries

I realized that it is possible to parse a separate line.

from datetime import datetime
from dateutil.parser import parse

dateVal = parse('2023-05-18T11:00:00Z')
print(dateVal.strftime('%d.%m.%Y %H:%M'))

But what if I want to analyze a list of rows, say, all the values of one column?

I asked myself, I answered myself

from datetime import datetime
from dateutil.parser import parse

for date in date_list:
    dateVal = parse(date)
    print(dateVal.strftime('%d.%m.%Y %H:%M'))

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.