Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added date-calc project #586

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
41 changes: 41 additions & 0 deletions projects/Date-Duration-Calc/date_calc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
from datetime import datetime, timedelta

#This project will allow the user to input two dates and the program
#will return the difference between the two dates

class Date:
def __init__(self, date1, date2):
self.date1 = date1
self.date2 = date2
self.request = 1

def calculate_difference(self):
time_difference = self.date2 - self.date1
self.days = time_difference.days

def calculate_years_weeks_days(self):
self.years = self.days // 365
self.remaining_days = self.days % 365
self.weeks = self.remaining_days // 7
self.days = self.remaining_days % 7

def get_date_input(self):
date1_str = input("Enter the first date (YYYY-MM-DD): ")
date2_str = input("Enter the second date (YYYY-MM-DD): ")
self.date1 = datetime.strptime(date1_str, "%Y-%m-%d")
self.date2 = datetime.strptime(date2_str, "%Y-%m-%d")

def display_result(self):
print(f"Years: {self.years}")
print(f"Weeks: {self.weeks}")
print(f"Days: {self.days}")

def calculate_and_display(self):
self.calculate_difference()
self.calculate_years_weeks_days()
self.display_result()

date_calculator = Date(None, None)

date_calculator.get_date_input()
date_calculator.calculate_and_display()