1

Below I have the format of a date and time I receive and I want to change it to the following format (in python). I essentially want to add a new column in my dataframe that has the date in the second format.

Received format: 2019-11-20T01:04:18+01:00

Format wanted: 20-11-19 1:04

If anyone knows the code to convert it, it would be very helpful, thank you!

Vasilis
  • 143
  • 8

2 Answers2

0

You simply use strftime() and strptime(). Please refer to documentation here: https://docs.python.org/2/library/datetime.html#strftime-and-strptime-behavior

Laimonas Sutkus
  • 2,177
  • 1
  • 12
  • 33
0

below thanks

import datetime
d = datetime.datetime.strptime('2019-11-20T01:04:18', '%Y-%m-%dT%H:%M:%S')
print d.strftime('%d-%m-%y %H:%M')

and to get week number

print d.isocalendar()[1]
Mike
  • 45
  • 5
  • It works thank you very much. Do you by any chance know how to add the week number in a different column? For example, that date is within week 47. – Vasilis Nov 22 '19 at 10:29
  • `print d.isocalendar()[1]` ammended above to show – Mike Nov 22 '19 at 15:33