Set year, month and day to the date in PHP
Description
The following code shows how to set year, month and day to the date.
Example
//from w ww .j a va 2s . co m
<?php
$date = new DateTime();
$date->setDate(2014, 2, 3);
echo $date->format('Y-m-d');
$date->setDate(2001, 2, 28);
echo $date->format('Y-m-d') . "\n";
$date->setDate(2001, 2, 29);
echo $date->format('Y-m-d') . "\n";
$date->setDate(2001, 14, 3);
echo $date->format('Y-m-d') . "\n";
?>
The code above generates the following result.