Days between dates: Difference between revisions
Content added Content deleted
(→{{header|Excel}}: Added an Excel example (using a LAMBDA expression to map over an array of dates)) |
|||
Line 723: | Line 723: | ||
272 |
272 |
||
</pre> |
</pre> |
||
=={{header|Excel}}== |
|||
===LAMBDA=== |
|||
Excel dates are numbers counting days since the start of January 1900, and arithmetic operations can be applied to them directly. |
|||
(Unless entered as strings, they differ from other numbers only in the display format applied to the containing cell). |
|||
The lambda expression below maps over an array of date strings, defining a new array of the differences, in units of one day, between today's date and those earlier dates. |
|||
(See [https://www.microsoft.com/en-us/research/blog/lambda-the-ultimatae-excel-worksheet-function/ LAMBDA: The ultimate Excel worksheet function]) |
|||
{{Works with|Office 365 betas 2021}} |
|||
{{Out}} |
|||
The formula in cell B2 defines the array of day counts which populate the range '''B2:B5''' |
|||
{| class="wikitable" |
|||
|- |
|||
|||style="text-align:right; font-family:serif; font-style:italic; font-size:120%;"|fx |
|||
! colspan="4" style="text-align:left; vertical-align: bottom; font-family:Arial, Helvetica, sans-serif !important;"|=LAMBDA(dateString, TODAY() - DATEVALUE(dateString) )(C2#) |
|||
|- style="text-align:center; font-family:Arial, Helvetica, sans-serif !important; background-color:#000000; color:#ffffff;" |
|||
| |
|||
| A |
|||
| B |
|||
| C |
|||
| D |
|||
|- |
|||
| style="text-align:center; font-family:Arial, Helvetica, sans-serif !important; background-color:#000000; color:#ffffff" | 1 |
|||
| |
|||
| style="font-weight:bold" | Difference in days |
|||
| style="font-weight:bold" | Earlier date |
|||
| style="font-weight:bold" | Today |
|||
|- |
|||
| style="text-align:center; font-family:Arial, Helvetica, sans-serif !important; background-color:#000000; color:#ffffff" | 2 |
|||
| |
|||
| style="text-align:right; background-color:#cbcefb" | 39020 |
|||
| 1914-07-28 |
|||
| style="text-align:right" | 2021-05-27 |
|||
|- |
|||
| style="text-align:center; font-family:Arial, Helvetica, sans-serif !important; background-color:#000000; color:#ffffff" | 3 |
|||
| |
|||
| style="text-align:right" | 37088 |
|||
| 1919-11-11 |
|||
| |
|||
|- |
|||
| style="text-align:center; font-family:Arial, Helvetica, sans-serif !important; background-color:#000000; color:#ffffff" | 4 |
|||
| |
|||
| style="text-align:right" | 29916 |
|||
| 1939-07-01 |
|||
| |
|||
|- |
|||
| style="text-align:center; font-family:Arial, Helvetica, sans-serif !important; background-color:#000000; color:#ffffff" | 5 |
|||
| |
|||
| style="text-align:right" | 27661 |
|||
| 1945-09-02 |
|||
| |
|||
|} |
|||
=={{header|Factor}}== |
=={{header|Factor}}== |