Python Forum
How To Create A "Birthday Calculator" in Python?
Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How To Create A "Birthday Calculator" in Python?
#1
Hi, I'm relatively new to Python and I want to create a program with Python that can calculate how many days are left until your birthday. However I'm stuck because someone's birthday may have already happened this year and then the program doesn't work for them and I can't find a way to make it dynamic without having to edit the date everyday. Can someone offer a fix? Highly appreciated, thanks.
Reply
#2
The following page explains, using examples, most of the datetime methods: https://pymotw.com/3/datetime/

here are some helpers:

import datetime

# to get today's date
today = datetime.date.today()

# to calculate date for Feb 29, 2012 (a leap year)
thedate = datetime.date(2012, 2, 29)

# to get delta in days form today (this is an absolute value)
delta = today - thedate

print(f"The delta is {delta.days} days")
Output:
The delta is 3509 days
Reply
#3
its just as simple as asking the user if they're birthday has passed this year
birthday_has_pass_this_year = input("has your birthday passed this year? (y/n)")
Reply
#4
If the birth day and month have already passed for the current year then use the following year.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Need some help trying to get my Python mortgage amortization calculator to work prope IamSirAskAlot 4 15,667 Feb-12-2024, 10:53 PM
Last Post: BerniceBerger
  New to python, trying to make a basic calculator AthertonH 2 1,113 Apr-14-2022, 03:33 PM
Last Post: AthertonH
  python calculator only using decomposing functions kirt6405 1 1,731 Jun-19-2021, 12:52 AM
Last Post: bowlofred
  Python calculator divide by zero help dock1926 4 5,753 Jan-20-2020, 05:15 PM
Last Post: michael1789
  Python Program to Make a Simple Calculator jack_sparrow007 2 10,096 Oct-19-2018, 08:32 AM
Last Post: volcano63
  Creating a Calculator with Python KatherineHov 8 7,651 Aug-03-2017, 02:13 PM
Last Post: sparkz_alot
  Python Calculator Application MemeStealer 6 7,598 Jul-21-2017, 08:42 PM
Last Post: MemeStealer

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020