FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
JavaScript/Conversions/DateDayDifference.js at master · MMABSOUT/JavaScript · GitHub
MMABSOUT
/
JavaScript
Public
forked from
TheAlgorithms/JavaScript
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
JavaScript
/
Conversions
/
DateDayDifference.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
36 lines (29 loc) · 1000 Bytes
Breadcrumbs
JavaScript
/
Conversions
/
DateDayDifference.js
Copy path
File metadata and controls
36 lines (29 loc) · 1000 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
/*
DateDayDifference Method
------------------------
DateDayDifference method calculates the number of days between two dates.
Algorithm & Explanation : https://ncalculators.com/time-date/date-difference-calculator.htm
*/
import
{
isLeapYear
}
from
'../Maths/LeapYear'
import
{
parseDate
}
from
'../Timing-Functions/ParseDate'
const
DateToDay
=
(
dd
,
mm
,
yyyy
)
=>
{
return
(
365
*
(
yyyy
-
1
)
+
Math
.
floor
(
(
yyyy
-
1
)
/
4
)
-
Math
.
floor
(
(
yyyy
-
1
)
/
100
)
+
Math
.
floor
(
(
yyyy
-
1
)
/
400
)
+
dd
+
Math
.
floor
(
(
367
*
mm
-
362
)
/
12
)
+
(
mm
<=
2
?
0
:
isLeapYear
(
yyyy
)
?
-
1
:
-
2
)
)
}
const
DateDayDifference
=
(
date1
,
date2
)
=>
{
const
firstDate
=
parseDate
(
date1
)
const
secondDate
=
parseDate
(
date2
)
return
Math
.
abs
(
DateToDay
(
secondDate
.
day
,
secondDate
.
month
,
secondDate
.
year
)
-
DateToDay
(
firstDate
.
day
,
firstDate
.
month
,
firstDate
.
year
)
)
}
// Example : DateDayDifference('17/08/2002', '10/10/2020') => 6630
export
{
DateDayDifference
}
Back
|
FazBrowse Home
|
New Git URL