I am a rookie python programmer and I need to write a script to check if a given date (passed as a string in the form \'Month, day year\') is the third Friday of the month. I am
This should do it:
from datetime import datetime
def is_third_friday(s):
d = datetime.strptime(s, '%b %d, %Y')
return d.weekday() == 4 and 15 <= d.day <= 21
Test:
print is_third_friday('Jan 18, 2013') # True
print is_third_friday('Feb 22, 2013') # False
print is_third_friday('Jun 21, 2013') # True
print is_third_friday('Sep 20, 2013') # True