/
Days_Between_Dates.py
67 lines (49 loc) · 2.09 KB
/
Days_Between_Dates.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# -*- coding: utf-8 -*-
"""
Title: Date Difference Calculator
Description:
This Python script calculates the number of days between a series of dates
and the first date listed. It is designed to help users quickly understand
the time intervals between key dates in a project or event timeline. The
script takes a list of dates in MM/DD/YYYY format and outputs the number
of days each date is from the first date on the list.
Usage:
Ensure you have Python installed on your system.
The script can be run from the command line or integrated into larger Python projects.
Modify the 'dates' list variable with your specific dates before running.
Requirements:
Python 3.x
No external libraries are required for the basic functionality.
Author:
Ibrahim Oladepo
Contributors:
ChatGPT - OpenAI's language model was consulted for assistance with code logic
and documentation.
License:
**
Example:
To run the script, ensure the 'dates' list contains your dates in the correct format.
Run the script using a Python interpreter:
$ python date_difference_calculator.py
Output will be displayed in the terminal or command prompt.
Notes:
This script is for educational and practical purposes. It can be modified
or expanded based on user requirements. For more complex date manipulations,
consider using libraries like pandas or numpy.
"""
from datetime import datetime
# List of dates in MM/DD/YYYY format
# dates = [
# "9/7/2023", "9/26/2023", "10/3/2023", "10/11/2023",
# "10/17/2023", "10/25/2023", "10/31/2023", "11/28/2023", "12/8/2023"
# ]
# dates = [
# "9/25/2023", "10/3/2023", "10/11/2023", "10/17/2023",
# "10/25/2023", "10/31/2023", "11/22/2023", "11/28/2023", "12/8/2023"
# ]
dates = ["9/12/2023", "9/26/2023", "10/3/2023", "10/11/2023", "10/17/2023"]
# Convert string dates to datetime objects
date_objects = [datetime.strptime(date, "%m/%d/%Y") for date in dates]
# Calculate the number of days from the first date
days_from_first_date = [(date - date_objects[0]).days for date in date_objects]
print(days_from_first_date)