Start New Discussion within our Software Development Community
"""Task: calculate this list (from vegaseat
http://www.daniweb.com/software-development/legacy-and-other-languages/threads/362098/1554079#post1554079)

All first workdays of each month in 2011:
 1) Mo  01/03/2011
 2) Tu  02/01/2011
 3) Tu  03/01/2011
 4) Fr  04/01/2011
 5) Mo  05/02/2011
 6) We  06/01/2011
 7) Fr  07/01/2011
 8) Mo  08/01/2011
 9) Th  09/01/2011
10) Mo  10/03/2011
11) Tu  11/01/2011
12) Th  12/01/2011


"""

from datetime import date, timedelta

def first_workday(month, year):
    first = date(year, month, 1)
    if first.weekday() < 5:
        return first
    return first + timedelta(days=7-first.weekday())

year = 2011
for month in range(1,13):
    print(' %2i) %s' % (month, first_workday(month,year).strftime('%a %m/%d/%Y')))
    
# Produces three letter weekday name instead of two letters

Specialties:
IT/Science/Contracts/Religious translation/interpreting FIN-ENG-FIN
Python programming

Not only way to do it of course (in spite of Python philosophy):

"""Task: calculate the list from vegaseat
http://www.daniweb.com/software-development/legacy-and-other-languages/threads/362098/1554079#post1554079)
"""

from datetime import date, timedelta

def first_workday(month, year):
    first = date(year, month, 1)
    return first if first.weekday() < 5 else first.replace(day=8 - first.weekday())

def table(year = 2011):
    print('\n'.join(' %2i) %s' %
                    (month, first_workday(month,year).strftime('%a %m/%d/%Y'))
                    for month in range(1,13)))
    # Produces three letter weekday name instead of two letters

table()
The article starter has earned a lot of community kudos, and such articles offer a bounty for quality replies.