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.

$today = new DateTime;
echo $today->format('Y-m-d ');
echo "<br>";
echo $today->format('Y-m-d');

The output is here


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 )


The output is here


Number of User Comments : 2

Click for more tutorial on Date & Time functions and Applications

More On Date Object
hgggfhhfhf ghf26-08-2014
how to display this (Fri May 14 12:03:24 IST
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.

HTML . MySQL. PHP. JavaScript. ASP. Photoshop. Articles. FORUM Contact us

©2000-2015 All rights reserved worldwide Privacy Policy Disclaimer