Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I check if a date field is in ISO format?

Using Python, is there a way check if a date field of a document in a MongoDB collection is in ISO format or in string format?

like image 384
Guisther Avatar asked Oct 20 '25 09:10

Guisther


1 Answers

You can make use of fromisoformat method in datetime library.

from datetime import date

try:
    date.fromisoformat(date_string)
except ValueError:
    print("Invalid isoformat string")
like image 93
Burak Özdemir Avatar answered Oct 22 '25 00:10

Burak Özdemir



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!