-4

I'm trying to convert dates from the utcnow (ISO 8601) function of azure logics apps in python:

this one returns the following format:

2018-02-07T13:30:17.2967490Z

so I'm doing it:

dateformat = datetime.strptime ("2018-02-07T13:30:17.2967490Z","%Y-%m-%dT%H:%M:%S.%fZ")

but it doesn't work, do you have any idea?

tdav
  • 11
  • 3
  • 1
    Define "doesn't work". Also, what's with the spaces between hours, minutes and seconds…?! – deceze Feb 20 '18 at 10:39

1 Answers1

2

You have spaces in your format. And after your microseconds (6 digits), you for some reason have the characters 0Z. So you could use this:

"%Y-%m-%dT%H:%M:%S.%f0Z"

As in:

>>> datetime.strptime ("2018-02-07T13:30:17.2967490Z","%Y-%m-%dT%H:%M:%S.%f0Z")
datetime.datetime(2018, 2, 7, 13, 30, 17, 296749)
khelwood
  • 55,782
  • 14
  • 81
  • 108
  • Hello thank you space just come from my cut and paste sorry will it also work for a date in this format? 2018-02-07T15:41:49.7447688Z – tdav Feb 20 '18 at 10:44
  • Where are you getting these weirdly formatted dates? – khelwood Feb 20 '18 at 10:44
  • from the utcnow() function from azure logic apps see https://learn.microsoft.com/en-us/azure/logic-apps/logic-apps-workflow-definition-language – tdav Feb 20 '18 at 10:45
  • The python microsecond field only accepts 6 digits. The ISO8601 standard (as I read it) specifies at most 6 digits. So I don't know what reason there is for having 7 digits. – khelwood Feb 20 '18 at 10:52
  • Do you have any solution for that ? the picture : https://ibb.co/ccRF8H – tdav Feb 20 '18 at 10:56