Date time library


#1

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

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


#2

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


#3

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


#4

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


#5

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