MNB PHPExcelDeveloper Guide
v2.0.5

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
01
TODAY()

Insert the current date as a volatile Excel formula and apply a date number format.

EasyExcel formula
MnbExcel::formula()dateStyleColumns()
today.php
<?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');
02
NOW()

Insert the current date and time as a volatile Excel formula.

EasyExcel formula
MnbExcel::formula()datetimeStyleColumns()
now.php
<?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');
03
DATEDIF

Calculate elapsed years, months, or days between two dates.

MediumExcel formula
MnbExcel::date()MnbExcel::formula()
datedif.php
<?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');
04
EOMONTH

Return the last day of a month before or after a supplied date.

MediumExcel formula
MnbExcel::date()MnbExcel::formula()
eomonth.php
<?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');