SQL PHP HTML ASP JavaScript articles and free scripts to download
 

Date modify

This is another way to add or subtract a date object with different month , days ,year , hour , minutes , sec etc.
This function is supported by PHP 5.2 or higher versions. So if you are running 5.2 version the you can use modify function as add or sub functions are supported by PHP 5.3 and higher only.

How to know PHP version ?

Here is an example on how to use modify function.

<?Php
date_default_timezone_set ("Asia/Kolkata");
$date1=new DateTime("now") ;
echo $date1->format('d-m-Y');
echo "<br>";
$date2=$date1->modify('+5 day');
echo $date2->format('d-m-Y');
?>

The output is here

05-03-2012
10-03-2012

We can change the highlighted line like this

$date2=$date1->modify('+3 month +5 day -1 year ');

Output of this change is here

05-03-2012
10-06-2011




Further readings
PHP Date & Time functions
PHP Date Time
Validating Date: Checking if date exist
PHP Date Today
PHP yesterday and previous 7 days from today
PHP Date Format
Time stamp generator
Date selection drop down list box
mktime function to generate time stamp
Difference in Two dates by using mktime function
Finding month, weekday, day of the year etc for any date value
Breaking the date string to get month date and year using array













Post Comment This is for short comments only. Use the forum for more discussions.
Name
Email( not to be displayed)Privacy Policy
1+2=This is to prevent automatic submission by spammers. Please enter the result of the sum as asked

Join Our Email List
Email:  
For Email Newsletters you can trust
Date & Time
HTML . MySQL. PHP. JavaScript. ASP. Photoshop. Articles. FORUM Contact us

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