Find number of days between two given days. #21
ashutosh12mar
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Find difference between 2 dates.
d1=18-Aug-2022 to d2=10-Sep-2018
Step 1. We will remove the dates difference
difference1 is 18-1=17
and now d1 becomes 1-Aug-2022
difference2 = 10-1=9
and d2 becomes 1-Sep-2018
Now we need to find the difference between
d1=1-Aug-2022
to
d2=1-Sep-2018
Now, we will find the difference of months
Consider d1 which is 1-Aug=8-2022
We will reduce it to 1-Jan-2022
The months in the middle are
1=31,2=28,3=31,4=30,5=31,6=30,7=31
difference3=212
d1 becomes 1-Jan-2022
Similarly for d2=1-Sep=9-2018
1=31,2=28,3=31,4=30,5=31,6=30,7=31,8=31
difference4=243
d2 is 1-Jan-2018
The difference needed is now reduced to years only
from 1-1-2022 to 1-1-2018
The years in between are
2018=365, 2019=365, 2020=366, 2021=365
difference5 = 1461
Now, we have the following 5 differences
difference1=17
difference2 =9
difference3= 212
difference4=243
difference5=1461
Total days=difference1-difference2+difference3-difference4+difference5
=17 - 9 + 212 - 243 + 1461 = 1438
Implement this as a program.
Beta Was this translation helpful? Give feedback.
All reactions