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
21focused categories
5implementation paths
01TODAY()Insert the current date as a volatile Excel formula and apply a date number format.
EasyExcel formula+
Insert the current date as a volatile Excel formula and apply a date number format.
MnbExcel::formula()dateStyleColumns()<?php
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');02NOW()Insert the current date and time as a volatile Excel formula.
EasyExcel formula+
Insert the current date and time as a volatile Excel formula.
MnbExcel::formula()datetimeStyleColumns()<?php
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');03DATEDIFCalculate elapsed years, months, or days between two dates.
MediumExcel formula+
Calculate elapsed years, months, or days between two dates.
MnbExcel::date()MnbExcel::formula()<?php
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');04EOMONTHReturn the last day of a month before or after a supplied date.
MediumExcel formula+
Return the last day of a month before or after a supplied date.
MnbExcel::date()MnbExcel::formula()<?php
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');Was this guide useful?Use GitHub issues for corrections, missing examples, or unclear behavior.
Open an issue