Skip to content

Commit 4f6c850

Browse files
authored
Merge pull request #4703 from oleibman/issue1764
Documentation for Excel Date/timestamp Format
2 parents c944b1a + dc2d89e commit 4f6c850

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

docs/topics/autofilters.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ $columnFilter->createRule()
176176
In MS Excel, DateGroup filters provide a series of dropdown filter
177177
selectors for date values, so you can specify entire years, or months
178178
within a year, or individual days within each month.
179+
Note that cells covered by such a filter are expected to be in [Excel DateTime Format](./calculation-engine.md#excel-timestamps).
179180

180181
![04-02-dategroup-autofilter.png](./images/04-02-dategroup-autofilter.png)
181182

docs/topics/calculation-engine.md

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -194,20 +194,22 @@ Time functions in Excel will be a PHP `DateTime` object.
194194

195195
#### Excel Timestamps
196196

197-
If `RETURNDATE_EXCEL` is set for the Return Date Type, then the returned
198-
date value by any access to the Date and Time functions in Excel will be
199-
a floating point value that represents a number of days from the Excel
200-
base date. The Excel base date is determined by which calendar Excel
197+
Excel timestamps are stored as integer or floating point, where the integer portion represents the number of days since a base date,
198+
and the fraction portion represents the time of day (0 is midnight, 0.5 is noon, 0.999... is just before midnight the next day).
199+
The Excel base date is determined by which calendar Excel
201200
uses: the Windows 1900 or the Mac 1904 calendar. 1st January 1900 is the
202201
base date for the Windows 1900 calendar while 1st January 1904 is the
203202
base date for the Mac 1904 calendar.
204203

205-
It is possible for scripts to change the calendar used for calculating
206-
Excel date values by calling the
207-
`\PhpOffice\PhpSpreadsheet\Shared\Date::setExcelCalendar()` method:
204+
If `RETURNDATE_EXCEL` is set for the Return Date Type, then the returned
205+
date value by any access to the Date and Time functions in Excel will be
206+
a floating point value in Excel timestamp format (previous paragraph).
208207

208+
It is possible for scripts to change the calendar used for calculating
209+
Excel date values by calling:
209210
```php
210-
\PhpOffice\PhpSpreadsheet\Shared\Date::setExcelCalendar($baseDate);
211+
\PhpOffice\PhpSpreadsheet\Shared\Date::setExcelCalendar($baseDate); // static property, less preferred
212+
$spreadsheet->setExcelCalendar($baseDate); // instance property, preferred
211213
```
212214

213215
where the following constants can be used for `$baseDate`:
@@ -218,11 +220,10 @@ where the following constants can be used for `$baseDate`:
218220
The method will return a Boolean True on success, False on failure (e.g.
219221
if an invalid value is passed in).
220222

221-
The `\PhpOffice\PhpSpreadsheet\Shared\Date::getExcelCalendar()` method can
222-
be used to determine the current value of this setting:
223-
223+
The current value of this setting can be determined via:
224224
```php
225-
$baseDate = \PhpOffice\PhpSpreadsheet\Shared\Date::getExcelCalendar();
225+
$baseDate = \PhpOffice\PhpSpreadsheet\Shared\Date::getExcelCalendar(); // static
226+
$baseDate = $spreadsheet->getExcelCalendar(); // instance
226227
```
227228

228229
The default is `CALENDAR_WINDOWS_1900`.

0 commit comments

Comments
 (0)