Monday 2 February 2015

setDate - PHP

setDate

We can assign new date to any date object by using setDate function. Using this we can change the date object.
setDate(Year, month, day)
Here are some examples to set the date.
date_default_timezone_set('America/Chicago');
$today = new DateTime;
echo $today->format('Y-m-d ');
echo "<br>";
$today->setDate(13,11,20);
echo $today->format('Y-m-d');
The output is here
2015-02-02 
0013-11-20
IN above code we can change the setDate function parameters and check the output. We can change to higher values for year and month , the function will adjust it to the next values and display the correct dates. Here are the changes ( only )
$today->setDate(13,14,31);
The output is here
2015-02-02 
0014-03-03

0 comments:

Post a Comment