Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (47.6k points)

When using Python strftime, is there a way to remove the first 0 of the date if it's before the 10th, ie. so 01 is 1? Can't find a %thingy for that?

Thanks!

1 Answer

+1 vote
by (106k points)

You can use the below-mentioned code:-

>>> import datetime 

>>> d = datetime.datetime.now() 

>>>d.strftime('X%d/X%m/%Y').replace('X0','X').replace('X','') '5/5/2011'

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
4 answers

Browse Categories

...