0

Seems like the strptime function of the datetime class is limited to 6 digits when it comes parsing fractional seconds with %f (https://docs.python.org/3/library/datetime.html#strftime-and-strptime-behavior)

Just wondering if there is a "decent" workaround other than writing myself regular expressions all the way just in order to achieve pretty much the same thing that is already implemented for one more additional digit.

Same has already been reported here: https://github.com/getsentry/sentry/issues/1610

Natalie Perret
  • 8,013
  • 12
  • 66
  • 129

1 Answers1

1

If you have a fixed input format, you could just cut off the remaining bits:

>>> s = '2015-07-15T11:39:37.0341297Z'
>>> s[:26]
'2015-07-15T11:39:37.034129'
>>> datetime.strptime(s[:26], '%Y-%m-%dT%H:%M:%S.%f')
datetime.datetime(2015, 7, 15, 11, 39, 37, 34129)
poke
  • 369,085
  • 72
  • 557
  • 602
  • I thought about that too, seems there is not real workaround out there for making datetime time part dealing with fractional microseconds / nanoseconds – Natalie Perret Mar 24 '17 at 16:52
  • 1
    Due to how the microseconds are internally stored (as microseconds :P), I don't think it would be possible for the datetime module to support higher precisions. – poke Mar 24 '17 at 17:55
  • Aw, guess it means need another lib to supper higher precisions then. Thanks anyway ~~ – Natalie Perret Feb 09 '23 at 02:41