I am trying to use datetime module. I need the month to come back as a INT with the ZERO in front. in the form as 01 for JAN, 02 for FEB etc etc. I can get 1 by using,
today = date.today()
m = today.month
I can get the correct format but not as an INT this way.
today.strftime("%m")
is there a simple way to get the desired format I need. I have looked in the reference and I am sure I am missing it, but could someone help.
seems to work.
Of course, you could take the less direct approach:
Or you could use old style string interpolation:
but I like the first one because I think it’s cool …
Finally, I don’t see what is wrong with
.strftime… even though you said you tried it, it works just fine for me:What it seems like you’re looking for is a special subclass of
intwhich knows how to “represent” itself when it printed:However, I would definitely not recommend using this approach, instead I would recommend using string formatting or string interpolation as I’ve done above on the integer objects when you need to represent the integers as strings.