Solihull
Solihull

Reputation: 7139

Problem with datetime module-Python

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!

Upvotes: 0

Views: 238

Answers (2)

Nadia Alramli
Nadia Alramli

Reputation: 114933

%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

Upvotes: 3

sth
sth

Reputation: 229563

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

Upvotes: 1

Related Questions