0

if we want to write the date to a csv it will be written in 'yyyy-mm-dd' format but I want to write in 'dd-mm-yyyy'. how to achieve this.

Write date in different format in datetime module.

  • 1
    Does this answer your question? [Python: How to convert datetime format?](https://stackoverflow.com/questions/6288892/python-how-to-convert-datetime-format) – FObersteiner Dec 30 '22 at 07:56

1 Answers1

1

You can use strftime function!

It's behaviour is explained in this section of documentation.

For your case, the format is as follows:

>>> now = dt.datetime.now()
>>> now
datetime.datetime(2022, 12, 30, 9, 37, 54, 218596)
>>> now.strftime("%d-%m-%Y")
'30-12-2022'
Anton
  • 67
  • 1
  • 8
  • for fetching it is possible I know. but what to do if we want to insert the date(19-12-2000) to a csv using datetime in the same format. – rajram333 Dec 30 '22 at 08:43