Help with date and time python


#1

HI,
So I am trying to print out a string that consists of the year and day in digits but the month name. So far I got this written down:

from datetime import datetime
now = datetime.now()
current_year = now.year
current_month = now.month
current_day = now.day
current_hour = now.hour
current_minute = now.minute
print " the year is %s, the month is (now.strftime(’%B’)) and the day is %s" %(current_year,current_day)

I am receiving the following error:
File “python”, line 8, in
ValueError: unsupported format character ‘B’ (0x42) at index 47

Any ideas what I did wrong ad how to fix this?
Thanks

File “python”, line 8, in
ValueError: unsupported format character ‘B’ (0x42) at index 47


#2

That says it all.

Replace that B with a valid format character.


#3

but isnt using that 'B" the way to bring to the string the month name?


#4

That expression cannot be written inside the string template. Create a %s placeholder in the template, and move the expression to the arguments list.