Skip to content

Commit

Permalink
Add DAY function description
Browse files Browse the repository at this point in the history
  • Loading branch information
stevethesleeve authored and nhatcher committed Jan 1, 2025
1 parent 0dd26e8 commit 564d4ba
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 6 deletions.
4 changes: 4 additions & 0 deletions docs/src/.vitepress/config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ export default defineConfig({
text: "Units",
link: "/features/units",
},
{
text: "Serial Numbers",
link: "/features/serial-numbers",
},
{
text: "Unsupported Features",
link: "/features/unsupported-features",
Expand Down
33 changes: 33 additions & 0 deletions docs/src/features/serial-numbers.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
layout: doc
outline: deep
lang: en-US
---

# Serial Numbers
::: warning
**Note:** This draft page is under construction 🚧
:::
**Note**: For convenience, dates presented on this page are formatted in accordance with the ISO 8601 international standard. IronCalc can recognize and display dates in other formats.

IronCalc stores dates and times as positive numbers, referred to as *serial numbers*. Serial numbers can be formatted to display the date and time.

The integer part of a serial number represents the date, as a count of the days since the fixed starting date of 1899-12-30. Hence dates are represented by a unique, sequential integer value, for example:
* 1 corresponds to 1899-12-31.
* 2 corresponds to 1900-01-01.
* 36,526 corresponds to 2000-01-01.
* 45,658 corresponds to 2025-01-01.
* 2,958,465 corresponds to 9999-12-31.

To illustrate the concept, type the value 2 into an empty cell that is initially formatted as a number. When you subsequently change the cell to a date format, it will update to show the date 1900-01-01.

The fractional part of a serial number represents time, as a fraction of the day. For example:
* 0.0 corresponds to 00:00:00 (midnight)
* 0.041666667 corresponds to 01:00:00.
* 0.5 corresponds to 12:00:00 (noon)
* 0.75 corresponds to 18:00:00.
* 0.99 corresponds to 23:45:36.

Since date-times are stored as numbers, they can be used for arithmetic operations in formulas. For example, it is possible to determine the difference between two dates by subtracting one serial number from the other.

**Note**: A #VALUE! error is reported if a date-formatted cell contains a number less than 1 or greater than 2,958,465.
2 changes: 1 addition & 1 deletion docs/src/functions/date-and-time.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ You can track the progress in this [GitHub issue](https://github.com/ironcalc/Ir
| DATE | <Badge type="tip" text="Available" /> ||
| DATEDIF | <Badge type="info" text="Not implemented yet" /> ||
| DATEVALUE | <Badge type="info" text="Not implemented yet" /> ||
| DAY | <Badge type="tip" text="Available" /> | |
| DAY | <Badge type="tip" text="Available" /> | [DAY](date_and_time/day) |
| DAYS | <Badge type="info" text="Not implemented yet" /> ||
| DAYS360 | <Badge type="info" text="Not implemented yet" /> ||
| EDATE | <Badge type="tip" text="Available" /> ||
Expand Down
36 changes: 31 additions & 5 deletions docs/src/functions/date_and_time/day.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,35 @@ layout: doc
outline: deep
lang: en-US
---

# DAY

# DAY function
::: warning
🚧 This function is implemented but currently lacks detailed documentation. For guidance, you may refer to the equivalent functionality in [Microsoft Excel documentation](https://support.microsoft.com/en-us/office/excel-functions-by-category-5f91f4e9-7b42-46d2-9bd1-63f26a86c0eb).
:::
**Note:** This draft page is under construction 🚧
:::
## Overview
DAY is a function of the Date and Time category that extracts the day of the month from a valid date [serial number](/features/serial-numbers.md), returning a number in the range [1, 31].
## Usage
### Syntax
**DAY(<span title="Number" style="color:#1E88E5">date</span>) => <span title="Number" style="color:#1E88E5">day</span>**
### Argument descriptions
* *date* ([number](/features/value-types#numbers), required). The date for which the day of the month is to be calculated, expressed as a [serial number](/features/serial-numbers.md) in the range [0, 2958465]. The value 0 corresponds to the date 1899-12-30, while 2958465 corresponds to 9999-12-31.
### Additional guidance
If the supplied _date_ argument has a fractional part, DAY uses its [floor value](https://en.wikipedia.org/wiki/Floor_and_ceiling_functions).
### Returned value
DAY returns an integer [number](/features/value-types#numbers) in the range [1, 31], that is the day of the month according to the [Gregorian calendar](https://en.wikipedia.org/wiki/Gregorian_calendar).
### Error conditions
* In common with many other IronCalc functions, DAY propagates errors that are found in its argument.
* If no argument, or more than one argument, is supplied, then DAY returns the [`#ERROR!`](/features/error-types.md#error) error.
* If the value of the *date* argument is not (or cannot be converted to) a [number](/features/value-types#numbers), then DAY returns the [`#VALUE!`](/features/error-types.md#value) error.
* For some argument values, DAY may return the [`#DIV/0!`](/features/error-types.md#div-0) error.
* If date is less than 0, or greater than 2,958,465, then DAY returns the [`#NUM!`](/features/error-types.md#num) error.
* At present, DAY does not accept a string representation of a date literal as an argument. For example, the formula `=DAY("2024-12-31")` returns the [`#VALUE!`](/features/error-types.md#value) error.
<!--@include: ../markdown-snippets/error-type-details.txt-->
## Details
IronCalc utilizes Rust's [chrono](https://docs.rs/chrono/latest/chrono/) crate to implement the DAY function.
## Examples
[See some examples in IronCalc](https://app.ironcalc.com/?example=day).

## Links
* See also IronCalc's [MONTH](/functions/date_and_time/month.md) and [YEAR](/functions/date_and_time/year.md) functions.
* Visit Microsoft Excel's [DAY function](https://support.microsoft.com/en-gb/office/day-function-8a7d1cbb-6c7d-4ba1-8aea-25c134d03101) page.
* Both [Google Sheets](https://support.google.com/docs/answer/3093040) and [LibreOffice Calc](https://wiki.documentfoundation.org/Documentation/Calc_Functions/DAY) provide versions of the DAY function.
Binary file modified xlsx/tests/docs/DAY.xlsx
Binary file not shown.

0 comments on commit 564d4ba

Please sign in to comment.