Re: Adding one month to a given date

From: Date: Mon, 02 Feb 2004 22:42:46 +0000
Subject: Re: Adding one month to a given date
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-176632@lists.php.net to get a copy of this message
here's a thought: ----------------- // using strtotime() you can turn your date into a unixtimestamp. e.g. $unixTimeStamp = strtotime('2003-10-19'); // using getdate($unixTimeStamp) you can get the consituent parts of the // date. e.g. $dateParts = getdate($unixTimeStamp); // then create a new unixtimestamp with mktime() e.g. $newUnixTimeStamp = mktime($dateParts['hours'], $dateParts['minutes'], $dateParts['seconds'], $dateParts['mon'] + 1, $dateParts['mday'], $dateParts['year']); // now you need to format the unixtimestamp so its humanly readable e.g. echo strftime('%Y-%m-%d', $newUnixTimeStamp); ---- tip: mktime() is a great tool for date calculations! check the comments on PHP site (page for the mktime() function) for tips on this. hope it helps (the above may contain typos!) rgds, jochem merlin wrote:
Hi there, I am trying to add one month to a given date. Somehow I am lost inbetween mktime, date and unix timestamps ;-( Can anybody give me a hint on that? The date format I do have is: 2003-10-19 Guess this does not work: $ptm = '2003-10-19'; $ptm = 1 + mktime('YmdHis',$ptm); Thanx for any help, Merlin


« previous php.general (#176632) next »