How to print in DD-MM-YYYY


#1

Let’s say today is 6th Feb 2018.
I want to print 06/02/2018
CODE:

from datetime import datetime
now = datetime.now()

print ‘%s/%s/%s’ %(now.day, now.month, now.year)

RESULT:
6/2/2018

How can I get 06/02/2018 ?


#2

strftime is what you are looking for:

https://docs.python.org/2/library/datetime.html#strftime-and-strptime-behavior

if you want to display a data in specific way.


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.