Write a Python program to find the born in the previous millennium or during this millennium given Birthday date


The program is written in Python and is used to determine if the user was born in the previous millennium or the current millennium. The program uses the datetime module to work with dates.

The program prompts the user to input their birthdate in the format dd-mm-yyyy. The input is then parsed into a datetime object using the strptime() method with the format string "%d-%m-%Y".

Next, the program compares the parsed date with the date datetime(2000, 1, 1) which represents the start of the current millennium. If the parsed date is earlier than this date, then the program prints "You were Born in the Previous Millennium". Otherwise, it prints "You were Born During this Millennium".

The program makes use of the datetime constructor to create the date datetime(2000, 1, 1) and the strftime() method is not used in the program.

Source Code

from datetime import datetime
 
dob = input("Enter your Birthday (dd-mm-yyyy) : ")
res = datetime.strptime(dob, "%d-%m-%Y")
 
if res < datetime(2000, 1, 1):
    print("You were Born in the Previous Millennium")
else:
    print("You were Born During this Millennium")

Output

Enter your Birthday (dd-mm-yyyy) : 8-6-2014
You were Born During this Millennium

Example Programs