メインコンテンツまでスキップ
Version: Fegg 5.x(開発版)

Date::addMonth

Add months to a date

Description​

public string Date::addMonth( string $dateTime, int $interval, [ string $format = 'Y-m-d H:i:s' ] )

Returns $dateTime plus $interval months, formatted with date() format $format. When the day does not exist in the target month, the last day of that month is used. The time is reset to 00:00:00.

Arguments​

NameData typeDefaultRemarks
$dateTimestringBase date
$intervalintNumber of months (negative: before)
$formatstring'Y-m-d H:i:s'date() format of the result

Example​

Controller
use Fegg\Tool\Date;

$date = new Date();

echo $date->addMonth('2024-01-31', 1); // -> "2024-02-29 00:00:00"
echo $date->addMonth('2024-04-15', -6, 'Y/m/d'); // -> "2023/10/15"