faqts : Computers : Programming : Languages : PHP

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

26 of 49 people (53%) answered Yes
Recently 7 of 10 people (70%) answered Yes

Entry

increment in date variable

Nov 28th, 2008 00:21
healthy man, dman, Edwin Chan, zahid bilal,


Let's say you want to increment 3 years, 2 months and decrement 1 day 
to the current date variable:
<?php
// set the date variable to NOW
$date=mktime();
// Check the current date
echo "Date is now: ".date("d-M-Y",$date)."<BR>";
// add 3 years, 2 months and subtract 1 day
$years_to_add =3;
$months_to_add=2;
$days_to_add  =-1;
$date=mktime(0,0,0,
             date("m",$date)+$months_to_add,
             date("d",$date)+$days_to_add,
             date("Y",$date)+$years_to_add
            );
// Check the current date again
echo "Date is now: ".date("d-M-Y",$date);
?>
http://www.healthdothealth.com
http://www.healthxhealth.com
http://www.mesotheliomainmesothelioma.com
http://www.healthfirewall.com
http://www.flathealth.com
http://www.healthbodyguard.com