-4

Got in touch with a few thousand dates using the following format:

2017-10-23T03:36:23.337+02:00

I only know that it's CET (central european time). Instead of trim the value manually, there is any solution that would give me this date in the format dd/mm/yy hh/mm/ss that I could use to subtract (find the diference between them) the dates without problems? Thanks for your inputs.

Here my code:

from_date="2017-10-23T03:36:23.337+02:00"
import time                
conv=time.strptime(from_date,"%Y-%m-%d %H:%M:%S")
print(time.strftime("%d/%m/%Y %H:%M:%S",conv))
Gonzalo
  • 1,084
  • 4
  • 20
  • 40
  • Possible duplicate of [How do I convert local time to UTC in Python?](https://stackoverflow.com/questions/79797/how-do-i-convert-local-time-to-utc-in-python) – voiDnyx Oct 25 '17 at 13:47
  • Possible duplicate of [How to print date in a regular format in Python?](https://stackoverflow.com/questions/311627/how-to-print-date-in-a-regular-format-in-python) – Ignacio Vergara Kausel Oct 25 '17 at 13:47
  • you want to convert that time to dd/mm/yy hh/mm/ss format? – DRPK Oct 25 '17 at 13:48
  • @DRPK thats right, but that I could use it later to find the diferences between dates. So it needs to continue as a date. thanks – Gonzalo Oct 25 '17 at 13:49
  • whats your code for that output format? – DRPK Oct 25 '17 at 13:51
  • @DRPK just updated the post with it. The format of the date that was given to me is strange. It has for instance a T in the middle. Is it possible to convert it to a normal date? Thanks. – Gonzalo Oct 25 '17 at 14:05

1 Answers1

0

With given format, you can use dateutil.parser.parse to handle it.

Here's some code:

d = "2017-10-23T03:36:23.337+02:00"
time = dateutil.parser.parse(d)
print(time.strftime("%d/%m/%y %H/%M/%S"))

The output is:

23/10/17 03/36/23