Discover Your Day Of Birth Using Python

ZennDogg
2 min readApr 25, 2022
Photo by Mohammad Rahmani on Unsplash

I was talking with a friend of mine a while back. He was brainstorming ideas for a birthday party for his tween. I had recently watched a show on TV about people with extraordinary abilities. One of the subjects could tell the day’s name of any given date. Sounded like an activity the kids might like using their birthdays. Told my friend I’d give it a try.

I needed two imports.

import calendar
import datetime

The calendar module has a function called day_name. The function returns a day name for a date, or in this case, is used to build a list of all the names of days.

We first entered the child’s name. Then the list of day names is generated.

name = "Marnie"
day_names = [i for i in calendar.day_name]

The next line of code takes the birth date (2011, 3, 11) and determines the day of the week as an integer, with 0=Monday, 1=Tuesday, 3=Wednesday, etc.

day_of_week = datetime.date(2011, 3, 11).weekday()
day = day_names[day_of_week]

The day_of_week integer is used to index the list of day names. This gives us the name of the day.

print(f'{name} was born on a {day}')

We then print the output.

Marnie was born on a FridayProcess finished with exit code 0

We provided a small printout for each of the kids. Happy to say it was a hit.

I hope you enjoyed this article. You can find more like this on my website. While there, please visit our advertiser’s page. I make a small commission on any purchase. That money is used to run and maintain the site. Cheers!

import calendar
import datetime
name = "Marnie"
day_names = [i for i in calendar.day_name]
day_of_week = datetime.date(2011, 3, 11).weekday()
day = day_names[day_of_week]
print(f'{name} was born on a {day}')

--

--

ZennDogg

Retired military, Retired US Postal Service, Defender of the US Constitution from all enemies, foreign and domestic, Self-taught in python