Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert DatetimeWithNanoseconds to date format in python firestore

I am trying to convert a firestore timestamp into milliseconds or a date format using python to perform a calculation using this date. Trying to parse it to date returns.

TypeError: strptime() argument 1 must be str, not DatetimeWithNanoseconds.

How can I convert a Firestore timestamp into milliseconds/date format in python? I need this to perform a calculation.

docs = db.collection(u'status').stream()

for doc in docs:
    doc_data = doc.to_dict()

    # TypeError: strptime() argument 1 must be str, not DatetimeWithNanoseconds
    utc_time = datetime.strptime(doc_data['start_date'], "%Y-%m-%dT%H:%M:%S.%fZ")
like image 417
barracuda Avatar asked Jan 20 '26 00:01

barracuda


1 Answers

It turns out that DatetimeWithNanoseconds inherits from datetime.datetime already

like image 147
Luke Avatar answered Jan 22 '26 13:01

Luke



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!