-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCalDate_INTIAL_TRIAL_CODE.py
267 lines (184 loc) · 9.16 KB
/
CalDate_INTIAL_TRIAL_CODE.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
#CREATED BY ~~~~ DEVANG SHAURYA PRATAP SINGH ~~~~
#______________________________________________________________________________________________________________
import Heaven #Heaven is just the file name of my functions
from datetime import date #import today's date
today_day=date.today().day
today_month=date.today().month
today_year = date.today().year
Heaven.credits()
#______________________________________________________________________________________________________________
Heaven.instructions() #used self maded function of instructions
#______________________________________________________________________________________________________________
while True: #done this to execute this program multiple times
print()
print()
#______________________________________________________________________________________________________________
a=(input('Enter Task Number 1 or 2: ---')) #taking task number
Heaven.task_number(a)
print()
print()
#______________________________________________________________________________________________________________
date=int(input('Enter Date :')) #date 1
while date>31:
print ('Don\'t be over smart enter valid date')
date=int(input('Enter Date :'))
month=int(input('Enter Month:')) #month1
while month>12:
print ('Don\'t be over smart enter valid month')
month=int(input('Enter Month:'))
year=int(input('Enter Year :')) #year1
print()
print()
#______________________________________________________________________________________________________________
if a=="1":
date2=int(input('Enter Date2 :')) #date 2
while date2>31:
print ('Don\'t be over smart enter valid date')
date2=int(input('Enter Date2 :'))
month2=int(input('Enter Month2:')) #month2
while month2>12:
print ('Don\'t be over smart enter valid month')
month2=int(input('Enter Month2:'))
year2=int(input('Enter Year2 :')) #year2
#______________________________________________________________________________________________________________
elif a=="2":
print ('Today\'s date:-',today_day,'/',today_month,'/',today_year) # putted this command for time period from today
date2=today_day
month2=today_month
year2=today_year
#______________________________________________________________________________________________________________
(Date1)=str(date)+'/'+str(month)+'/'+str(year) #GETING DATE 1
(Date2)=str(date2)+'/'+str(month2)+'/'+str(year2) #GETING DATE 2
#______________________________________________________________________________________________________________
#below i have defined the number of days in differnt months
jan=31
if year%4==0: #feb problem1
feb=29
else:
feb=28
if year2%4==0: #feb problem2
feb2=29
else:
feb2=28
mar=31
apr=30
may=31
jun=30
jul=31
aug=31
sep=30
oct=31
nov=30
dec=31
#______________________________________________________________________________________________________________
if month==1: #depending upon the number of months it is calculating the number of days in date 1
dmonth=0
elif month==2:
dmonth=jan
elif month==3:
dmonth=jan+feb
elif month==4:
dmonth=jan+feb+mar
elif month==5:
dmonth=jan+feb+mar+apr
elif month==6:
dmonth=jan+feb+mar+apr+may
elif month==7:
dmonth=jan+feb+mar+apr+may+jun
elif month==8:
dmonth=jan+feb+mar+apr+may+jun+jul
elif month==9:
dmonth=jan+feb+mar+apr+may+jun+jul+aug
elif month==10:
dmonth=jan+feb+mar+apr+may+jun+jul+aug+sep
elif month==11:
dmonth=jan+feb+mar+apr+may+jun+jul+aug+sep+oct
else:
dmonth=jan+feb+mar+apr+may+jun+jul+aug+sep+oct+nov
if month2==1: #depending upon the number of months it is calculating the number of days in date 2
dmonth2=0
elif month2==2:
dmonth2=jan
elif month2==3:
dmonth2=jan+feb2
elif month2==4:
dmonth2=jan+feb2+mar
elif month2==5:
dmonth2=jan+feb2+mar+apr
elif month2==6:
dmonth2=jan+feb2+mar+apr+may
elif month2==7:
dmonth2=jan+feb2+mar+apr+may+jun
elif month2==8:
dmonth2=jan+feb2+mar+apr+may+jun+jul
elif month2==9:
dmonth2=jan+feb2+mar+apr+may+jun+jul+aug
elif month2==10:
dmonth2=jan+feb2+mar+apr+may+jun+jul+aug+sep
elif month2==11:
dmonth2=jan+feb2+mar+apr+may+jun+jul+aug+sep+oct
else:
dmonth2=jan+feb2+mar+apr+may+jun+jul+aug+sep+oct+nov
#______________________________________________________________________________________________________________
days1=int((year-1)*365.25+dmonth+date) #have divided by 365.25 because earth revolves sun in 365 and 1/4 days
days2=int((year2-1)*365.25+dmonth2+date2)
#______________________________________________________________________________________________________________
if days1>days2: #added new variable feb0 which will help later on
days_bet=days1-days2 #depending upon which date is new it take value of feb either by year1 or year2
feb0=feb
else:
days_bet=days2-days1
feb0=feb2
#______________________________________________________________________________________________________________
print()
print()
print(days_bet,"days are in between date1 and date2")
#______________________________________________________________________________________________________________
year_bet=int(days_bet//365.25)
RD=round(days_bet%365.25)
#______________________________________________________________________________________________________________
if RD<=jan: #this whole pyramid is created to calculate number of months efficiently
RMonth=0 #as every month is not of exactly 30 days so I have created this to calculate
RDays=RD #correct number of days and months
elif jan<RD<=(jan+feb0):
RMonth=1
RDays=RD-(jan)
elif jan+feb0<RD<=(jan+feb0+mar):
RMonth=2
RDays=RD-(jan+feb0)
elif jan+feb0+mar<RD<=(jan+feb0+mar+apr):
RMonth=3
RDays=RD-(jan+feb0+mar)
elif jan+feb0+mar+apr<RD<=(jan+feb0+mar+apr+may):
RMonth=4
RDays=RD-(jan+feb0+mar+apr)
elif jan+feb0+mar+apr+may<RD<=(jan+feb0+mar+apr+may+jun):
RMonth=5
RDays=RD-(jan+feb0+mar+apr+may)
elif jan+feb0+mar+apr+may+jun<RD<=(jan+feb0+mar+apr+may+jun+jul):
RMonth=6
RDays=RD-(jan+feb0+mar+apr+may+jun)
elif jan+feb0+mar+apr+may+jun+jul<RD<=(jan+feb0+mar+apr+may+jun+jul+aug):
RMonth=7
RDays=RD-(jan+feb0+mar+apr+may+jun+jul)
elif jan+feb0+mar+apr+may+jun+jul+aug<RD<=(jan+feb0+mar+apr+may+jun+jul+aug+sep):
RMonth=8
RDays=RD-(jan+feb0+mar+apr+may+jun+jul+aug)
elif jan+feb0+mar+apr+may+jun+jul+aug+sep<RD<=(jan+feb0+mar+apr+may+jun+jul+aug+sep+oct):
RMonth=9
RDays=RD-(jan+feb0+mar+apr+may+jun+jul+aug+sep)
elif jan+feb0+mar+apr+may+jun+jul+aug+sep+oct<RD<=(jan+feb0+mar+apr+may+jun+jul+aug+sep+oct+nov):
RMonth=10
RDays=RD-(jan+feb0+mar+apr+may+jun+jul+aug+sep+oct)
elif jan+feb0+mar+apr+may+jun+jul+aug+sep+oct+nov<RD<=(jan+feb0+mar+apr+may+jun+jul+aug+sep+oct+nov+dec):
RMonth=11
RDays=RD-(jan+feb0+mar+apr+may+jun+jul+aug+sep+oct+nov)
#______________________________________________________________________________________________________________
print(year_bet,'year(s) ',RMonth,'month(s) ',RDays,'day(s) are between',Date1,'and',Date2 )
print()
print()
#______________________________________________________________________________________________________________
Heaven.end_func() #used my end function
#______________________________________________________________________________________________________________
# I have spend my handful amount of time in making this so you should apprecite it :)
#this code is correctly calulating number days ,years and month ;keeping in mind the feb month problem