Adding 1 month to Unix Timestamp

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
seodevhead
Forum Regular
Posts: 705
Joined: Sat Oct 08, 2005 8:18 pm
Location: Windermere, FL

Adding 1 month to Unix Timestamp

Post by seodevhead »

Hey gang,

I'm trying to figure out how I can add 1-Month on to a "2008-05-09" style date. But I am converting that date to a Unix Timestamp first by doing the following:

Code: Select all

$capturedDate = '2008-06-20';
    $endDate = strtotime($capturedDate);
 
// Now I need to add 1 Month onto $endDate.
Anyone know how I can add 1-month onto $endDate using PHP? I've been looking high and low in the PHP manual under date/time functions, but can't find anything that will do it with a unix timestamp. Thanks for any help.
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: Adding 1 month to Unix Timestamp

Post by onion2k »

Call strtotime a second time... eg strtotime("+1 month", $endDate); ... you may even be able to do strtotime($captureDate." +1 month");
User avatar
seodevhead
Forum Regular
Posts: 705
Joined: Sat Oct 08, 2005 8:18 pm
Location: Windermere, FL

Re: Adding 1 month to Unix Timestamp

Post by seodevhead »

Boy... thanks so much Onion! That worked great! I hadn't realized you could double up like that. SWEET! :P
Post Reply