0

I have the following variable start_date:

start_date
Timestamp('2003-03-31 00:00:00')

I want it to become: 31-03-2003

so I want the minut hours seconds to be removed and also the format to change as %d%m%Y

Can anybody help? Luigi

Luigi87
  • 265
  • 4
  • 13
  • https://stackoverflow.com/questions/32969113/changing-the-format-of-timestamp-in-python This approach might help you – PeakyBlinder Aug 27 '20 at 14:22

1 Answers1

0

I solved it this way:

start_date = datetime.strptime(start_date, '%Y-%m-%d %H:%M:%S')
start_date = start_date.strftime('%d-%m-%Y')

Thanks

Luigi

Luigi87
  • 265
  • 4
  • 13
  • 1
    side note: if you're using Python 3.7 or higher, you can use `datetime.fromisoformat()` instead of `strptime` to parse timestamp strings of that format [pretty efficiently.](https://stackoverflow.com/questions/13468126/a-faster-strptime) – FObersteiner Aug 27 '20 at 19:31