Date examples
Date Excel examples, explained clearly.
Open a focused example to see the implementation path, copy-ready PHP, expected workbook behavior, and the production boundary that matters.
4examples in this category
21supported categories
5implementation paths
Monolithic library
Date examples with copy-ready, production-minded PHP.
Each example identifies the exact methods it uses and can be opened independently from the right-side index.
- 4
- examples
- 4
- documented methods
MnbExcel::formula()dateStyleColumns()<?php
declare(strict_types=1);
/*
Summary:
Insert the current date as a volatile Excel formula and apply a date number format.
Implementation note:
TODAY recalculates according to the spreadsheet application and client system date.
*/
use Mnb\PHPExcel\MnbExcel;
$rows = [[
'Report' => 'Daily sales',
'Report date' => MnbExcel::formula('TODAY()', date('Y-m-d')),
]];
MnbExcel::fromArray($rows)
->withHeader()
->dateStyleColumns(['Report date'], 'yyyy-mm-dd')
->save('today.xlsx');MnbExcel::formula()datetimeStyleColumns()<?php
declare(strict_types=1);
/*
Summary:
Insert the current date and time as a volatile Excel formula.
Implementation note:
Use a fixed MnbExcel::date() value instead when an immutable audit timestamp is required.
*/
use Mnb\PHPExcel\MnbExcel;
$rows = [[
'Process' => 'Inventory export',
'Generated at' => MnbExcel::formula('NOW()', date('Y-m-d H:i:s')),
]];
MnbExcel::fromArray($rows)
->withHeader()
->datetimeStyleColumns(['Generated at'], 'yyyy-mm-dd hh:mm:ss')
->save('now.xlsx');MnbExcel::date()MnbExcel::formula()<?php
declare(strict_types=1);
/*
Summary:
Calculate elapsed years, months, or days between two dates.
Implementation note:
DATEDIF is written for Excel recalculation. Use PHP DateTimeImmutable::diff() when the result is
needed before the workbook opens.
*/
use Mnb\PHPExcel\MnbExcel;
$rows = [[
'Start date' => MnbExcel::date('2020-04-15'),
'End date' => MnbExcel::date('2026-07-26'),
'Completed years' => MnbExcel::formula('DATEDIF(A2,B2,"Y")', 6),
]];
MnbExcel::fromArray($rows)
->withHeader()
->dateStyleColumns(['Start date', 'End date'])
->save('datedif.xlsx');MnbExcel::date()MnbExcel::formula()<?php
declare(strict_types=1);
/*
Summary:
Return the last day of a month before or after a supplied date.
Implementation note:
The month offset may be negative, zero, or positive.
*/
use Mnb\PHPExcel\MnbExcel;
$rows = [[
'Invoice date' => MnbExcel::date('2026-07-12'),
'Month end' => MnbExcel::formula('EOMONTH(A2,0)', '2026-07-31'),
'Next month end' => MnbExcel::formula('EOMONTH(A2,1)', '2026-08-31'),
]];
MnbExcel::fromArray($rows)
->withHeader()
->dateStyleColumns(['Invoice date', 'Month end', 'Next month end'])
->save('eomonth.xlsx');No matching example found.Try a method name, task, or result.
Was this guide useful?Use GitHub issues for corrections, missing examples, or unclear behavior.
Open an issue