Date time library


from datetime import datetime
now =
print β€œ%02d/%02d/%02d” %(,now.month,now.year)

After running this code why i get the now.year value printed in 4 digits (2018) ? :slight_smile:


02 arranges the number of digits displayed, but it won’t truncate numbers. It will just add leading zeroes when there aren’t enough digits

for example %05d would display 02018


Thanks for clarifying that , but now how can i get the date (Now.year) to be displayed in 2 digits format 18 instead of 2018


Have a look at strftime (or simply take the last two characters after converting the number to string)


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