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.
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.
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'