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-07-05
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-07-05
0014-03-03

Number of User Comments : 2


Google+
Click for more tutorial on Date & Time functions and Applications


More On Date Object
hgggfhhfhf ghf

26-08-2014

how to display this (Fri May 14 12:03:24 IST
2010)
slon

23-04-2015

Rather limited class. There is no easy way to get year, month, date etc. Stuid date difference returns a hole class istead of value in items I provide ('d', 'm', 'q' etc) as MSSQL & other conventional DateDiff functions do.

Post Comment This is for short comments only. Use the forum for more discussions.






OPINION POLL

What is the most important factor of a web site
HTML . MySQL. PHP. JavaScript. ASP. Photoshop. Articles. FORUM Contact us

©2000-2015 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer