Notes from the datetime and time modules

Needed to come up with a function that returns the current week in the form of m/d/year to m/d/year(example: 10/11/2015 to 10/17/2015) to enter into a web form.
disclaimer! my naming conventions are all over the place.

def MatrixWeekDates():
#current day
today = datetime.date.today()
#assign an integer value to today
weekDayNum = int(time.strftime('%w'))
#assign dates to begin and end the week
weekBegin = today - datetime.timedelta(days=(weekDayNum))
weekEnd = today + datetime.timedelta(days=(weekDayNum -6))
#assign variable with formatted(mm/dd/yyyy) string concatenation to meet requirements.
WeekDates = (weekBegin.strftime('%m/%d/%Y')) + " to " + (weekEnd.strftime('%m/%d/%Y'))
return WeekDates

This entry was posted in Tech. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *