How to get todays day in dd format in Python 2.7 -


how keep format of day , month having dd/mm?

currently if under 10 print single number 5 rather 05 or 08.

today = date.today()  print(today) print(today.day) print(today.month) 

output:

2015-08-05 5 8 

what want:

05 08 

you can use strftime:

print(today.strftime("%d")) print(today.strftime("%m")) 05 08 

a leading 0 means octal using python2 , invalid syntax in python3 need use string if want have leading 0. use str.format , pad not point when can date object.


Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -