Skip to content

Instantly share code, notes, and snippets.

@dicksontsai
Created August 11, 2019 07:48
Show Gist options
  • Save dicksontsai/128c8ae4c5645c63e1116d8b2da624df to your computer and use it in GitHub Desktop.
Save dicksontsai/128c8ae4c5645c63e1116d8b2da624df to your computer and use it in GitHub Desktop.
Simple script to print all dates of a month in "2006/01/02 (Mon)" format. Perfect for a monthly diary doc.
#!/usr/bin/env python3
from datetime import datetime, timedelta
import sys
USAGE = """
Print dates from the given start day to the end of the day's month.
Usage: print_dates.py yyyy/mm/dd
"""
if __name__ == '__main__':
if len(sys.argv) != 2:
print(USAGE)
sys.exit(1)
curr_date = datetime.strptime(sys.argv[1], '%Y/%m/%d')
start_year = curr_date.year
start_month = curr_date.month
date_strs = []
while curr_date.month == start_month and curr_date.year == start_year:
date_strs.append(curr_date.strftime('%Y/%m/%d (%a)'))
curr_date += timedelta(days=1)
for s in date_strs[::-1]:
print(s)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment