0

I have datetime in yyyy-MM-dd'T'HH:mm:ssZ i.e (2022-04-30T07:00:00+0000) format and I want it to be converted into %Y-%m-%d i.e 2022-04-30 format in python. Can anyone tell me how to do it?

I have tried date = datetime.strptime(end_time, "%Y-%m-%d") and
date = datetime.strptime(end_time, "%Y-%m-%d").date(), but it's not working.

martineau
  • 119,623
  • 25
  • 170
  • 301
  • Your format string has to cover the whole date/time string. – Klaus D. May 19 '22 at 15:09
  • @Klaus D. I only want the date (2022-04-30), so how can I get it, actually there is a condition in which I have to compare those dates but the format I have of one date is "%Y-%m-%d" and the format of another date I'm getting is "yyyy-MM-dd'T'HH:mm:ssZ" – Anshul Rajput May 19 '22 at 15:15
  • 1
    Does this answer your question? [How do I parse an ISO 8601-formatted date?](https://stackoverflow.com/questions/127803/how-do-i-parse-an-iso-8601-formatted-date) – FObersteiner May 19 '22 at 15:38
  • ...or just split the string on `T` ? – FObersteiner May 19 '22 at 15:39

0 Answers0