Skip to content

Instantly share code, notes, and snippets.

Created Apr 14, 2017
What would you like to do?
Python3.x: Print every Sunday
from datetime import datetime
from dateutil.relativedelta import relativedelta, SU
from dateutil.rrule import rrule, WEEKLY
import argparse
def main(args):
start = datetime.strptime(args.start_date, "%Y%m%d")
today =
rule = rrule(WEEKLY, byweekday=SU, dtstart=start, until=today)
print(*[ sunday.strftime("%Y%m%d") for sunday in list(rule)])
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument('start_date',help='Start Date as "YYYYmmdd"')
args = parser.parse_args()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment