Last active
August 29, 2015 14:04
-
-
Save makuk66/c68462d2d86701fd32a0 to your computer and use it in GitHub Desktop.
python date for alug
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import datetime | |
date=datetime.date(2014,7,17) | |
print('{d}'.format(d=date)) | |
for _ in range(12): | |
date=date+datetime.timedelta(days=21) | |
print('{d}'.format(d=date)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This was for http://lists.alug.org.uk/pipermail/main/2014-July/033313.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mak@crab 571 ~ $ python every21days.py | |
2014-07-17 | |
2014-08-07 | |
2014-08-28 | |
2014-09-18 | |
2014-10-09 | |
2014-10-30 | |
2014-11-20 | |
2014-12-11 | |
2015-01-01 | |
2015-01-22 | |
2015-02-12 | |
2015-03-05 | |
2015-03-26 | |
mak@crab 575 ~ $ python second-tue.py | |
first day of month is Wednesday 01 January 2014 | |
Tuesday #1 is Tuesday 07 January 2014 | |
Tuesday #2 is Tuesday 14 January 2014 | |
Second Tuesday: Tuesday 14 January 2014 | |
first day of month is Saturday 01 February 2014 | |
Tuesday #1 is Tuesday 04 February 2014 | |
Tuesday #2 is Tuesday 11 February 2014 | |
Second Tuesday: Tuesday 11 February 2014 | |
first day of month is Saturday 01 March 2014 | |
Tuesday #1 is Tuesday 04 March 2014 | |
Tuesday #2 is Tuesday 11 March 2014 | |
Second Tuesday: Tuesday 11 March 2014 | |
first day of month is Tuesday 01 April 2014 | |
Tuesday #1 is Tuesday 01 April 2014 | |
Tuesday #2 is Tuesday 08 April 2014 | |
Second Tuesday: Tuesday 08 April 2014 | |
first day of month is Thursday 01 May 2014 | |
Tuesday #1 is Tuesday 06 May 2014 | |
Tuesday #2 is Tuesday 13 May 2014 | |
Second Tuesday: Tuesday 13 May 2014 | |
first day of month is Sunday 01 June 2014 | |
Tuesday #1 is Tuesday 03 June 2014 | |
Tuesday #2 is Tuesday 10 June 2014 | |
Second Tuesday: Tuesday 10 June 2014 | |
first day of month is Tuesday 01 July 2014 | |
Tuesday #1 is Tuesday 01 July 2014 | |
Tuesday #2 is Tuesday 08 July 2014 | |
Second Tuesday: Tuesday 08 July 2014 | |
first day of month is Friday 01 August 2014 | |
Tuesday #1 is Tuesday 05 August 2014 | |
Tuesday #2 is Tuesday 12 August 2014 | |
Second Tuesday: Tuesday 12 August 2014 | |
first day of month is Monday 01 September 2014 | |
Tuesday #1 is Tuesday 02 September 2014 | |
Tuesday #2 is Tuesday 09 September 2014 | |
Second Tuesday: Tuesday 09 September 2014 | |
first day of month is Wednesday 01 October 2014 | |
Tuesday #1 is Tuesday 07 October 2014 | |
Tuesday #2 is Tuesday 14 October 2014 | |
Second Tuesday: Tuesday 14 October 2014 | |
first day of month is Saturday 01 November 2014 | |
Tuesday #1 is Tuesday 04 November 2014 | |
Tuesday #2 is Tuesday 11 November 2014 | |
Second Tuesday: Tuesday 11 November 2014 | |
first day of month is Monday 01 December 2014 | |
Tuesday #1 is Tuesday 02 December 2014 | |
Tuesday #2 is Tuesday 09 December 2014 | |
Second Tuesday: Tuesday 09 December 2014 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import datetime | |
year=2014 | |
for m in range(1,13): | |
date = datetime.date(year,m,1) | |
print date.strftime("first day of month is %A %d %B %Y") | |
count=0 | |
# for quick-and-dirty simplicity, we'll loop over days and report given days of the week. | |
# If you want more efficiency, use the isoweekday and use math to determine the next looked-for day, then add a week | |
while True: | |
# Mon=1, Tue=2 etc | |
if date.isoweekday() == 2: | |
count = count + 1 | |
print "Tuesday #{} is {}".format(count, date.strftime("%A %d %B %Y")) | |
if count == 2: | |
print date.strftime("Second Tuesday: %A %d %B %Y") | |
break | |
date=date + datetime.timedelta(days=1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment