tags:

views:

89

answers:

2

How come this works:

import datetime
now = datetime.datetime.now()
month = '%d' % now.month

print month

But this doesn't?

import datetime
now = datetime.datetime.now()
month = '%m' % now.month

print month

Thanks!

+3  A: 

%m is not a supported format character for the % operator. Here is the list of supported formating characters for this operator

%m is valid when your are using strftime function to build a date string

Nadia Alramli
According to this-http://docs.python.org/library/time.html it is?
Solihull
Thanks, suddenly realised that rereading it! Dur!
Solihull
@Seamus Longinal: Those directives are specifically to the 'format' argument of time.strftime(format[, t])http://docs.python.org/library/time.html#time.strftime
GogaRieger
+1  A: 

'%d' is a format character that insert a "signed integer decimal", '%m' has no such meaning. The possible format characters are listed here.

sth