Jump to content

Days between dates: Difference between revisions

Added AutoHotkey
(Add JavaScript)
(Added AutoHotkey)
Line 287:
 
<pre>days between the two dates: 291</pre>
 
=={{header|AutoHotkey}}==
<lang AutoHotkey>db =
(
1995-11-21|1995-11-21
2019-01-01|2019-01-02
2019-01-02|2019-01-01
2019-01-01|2019-03-01
2020-01-01|2020-03-01
1902-01-01|1968-12-25
2090-01-01|2098-12-25
1902-01-01|2098-12-25
)
 
for i, line in StrSplit(db, "`n", "`r"){
D := StrSplit(line, "|")
result .= "Days between " D.1 " and " D.2 " : " Days_between(D.1, D.2) " Day(s)`n"
}
MsgBox, 262144, , % result
return
 
Days_between(D1, D2){
D1 := RegExReplace(D1, "\D")
D2 := RegExReplace(D2, "\D")
EnvSub, D2, % D1, days
return D2
}</lang>
{{out}}
<pre>Days between 1995-11-21 and 1995-11-21 : 0 Day(s)
Days between 2019-01-01 and 2019-01-02 : 1 Day(s)
Days between 2019-01-02 and 2019-01-01 : -1 Day(s)
Days between 2019-01-01 and 2019-03-01 : 59 Day(s)
Days between 2020-01-01 and 2020-03-01 : 60 Day(s)
Days between 1902-01-01 and 1968-12-25 : 24465 Day(s)
Days between 2090-01-01 and 2098-12-25 : 3280 Day(s)
Days between 1902-01-01 and 2098-12-25 : 71947 Day(s)</pre>
 
=={{header|AWK}}==
299

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.