Skip to content

Commit b1c299f

Browse files
committed
Counting Days
This script will calculate the days between today and X.
1 parent dde43d6 commit b1c299f

File tree

2 files changed

+79
-0
lines changed

2 files changed

+79
-0
lines changed

Python/Counting_Days/Readme.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Counting Days
2+
## Description
3+
A simple check that will tell the difference between today and the date given.
4+
- This can be useful to see how many days are between two dates, so helpful for programming purposes.
5+
- The app will give you a print out of the days, as a text string, and as a normal int.
6+
7+
### Language
8+
- [X] Python
9+
10+
### Checklist
11+
Name | About
12+
:------------------ | :------------------
13+
Counting Days | Shows the number of days between today and (date) given
14+
15+
### Usage
16+
To access the `timer`, this application imports the following modules.
17+
```python
18+
import os
19+
import time
20+
```
21+
22+
### Instructions to run this application
23+
24+
1. Download and Run the __counting_days.py__
25+
2. Enter the date you want a difference of
26+
3. The difference will be returned
27+
28+
##### Example Output
29+
Output will be shown as follows:
30+
```
31+
There are 5 days between now and (date)!
32+
5
33+
```

Python/Counting_Days/counting_days.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# import modules like 'os' and 'date'
2+
import os
3+
from datetime import date
4+
5+
# clear the console
6+
if os.name == "nt":
7+
os.system('cls')
8+
else:
9+
os.system('clear')
10+
11+
print("\nWelcome to Counting Days!\n")
12+
13+
# get the current day
14+
today = date.today()
15+
print("\nCurrent Day: ", today)
16+
17+
# User input for the date
18+
print("\nTell me about the day you wanted...")
19+
try:
20+
year = int(input("What Year? "))
21+
except ValueError:
22+
raise ValueError("Invalid Year! You must enter a number for the year.")
23+
try:
24+
month = int(input("What Month? "))
25+
except ValueError:
26+
raise ValueError("Invalid Month! You must enter a number for the month.")
27+
try:
28+
day = int(input("What Day? "))
29+
except ValueError:
30+
raise ValueError("Invalid Day! You must enter a number for the day.")
31+
32+
# try to build the date object
33+
try:
34+
futureday = date(year, month, day)
35+
except ValueError:
36+
raise ValueError("Invalid Date! You must enter a valid date.")
37+
38+
# Display message if date is before today.
39+
if today > futureday:
40+
raise ValueError("Invalid Date! You must pick a future date.")
41+
42+
# calculate and show date
43+
delta = futureday - today
44+
print("\nThere are", delta.days, "days between", today, "and", futureday, "!")
45+
46+

0 commit comments

Comments
 (0)