Days between dates: Difference between revisions
Content added Content deleted
(→{{header|Erlang}}: Reversed the order of the alternate functions.) |
(Add Factor) |
||
Line 44: | Line 44: | ||
daysbetween:between("2019-01-01", "2019-09-30"). |
daysbetween:between("2019-01-01", "2019-09-30"). |
||
272 |
272 |
||
</pre> |
|||
=={{header|Factor}}== |
|||
Factor supports the addition and subtraction of timestamps and durations with the <code>time+</code> and <code>time-</code> words. |
|||
<lang factor>USING: calendar calendar.parser formatting kernel math ; |
|||
: days-between ( ymd-str ymd-str -- n ) |
|||
[ ymd>timestamp ] bi@ time- duration>days abs ; |
|||
"2019-01-01" "2019-09-30" |
|||
"2016-01-01" "2016-09-30" ! leap year |
|||
[ |
|||
[ days-between ] 2keep |
|||
"There are %d days between %s and %s\n" printf |
|||
] 2bi@</lang> |
|||
{{out}} |
|||
<pre> |
|||
There are 272 days between 2019-01-01 and 2019-09-30 |
|||
There are 273 days between 2015-12-31 and 2016-09-30 |
|||
</pre> |
</pre> |
||