add 30 days to current date?

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
SmokyBarnable
Forum Contributor
Posts: 105
Joined: Wed Nov 01, 2006 5:44 pm

add 30 days to current date?

Post by SmokyBarnable »

Code: Select all

$now = time();
  $endtimefrom = gmdate('Y-m-d H:i:s', $now);
I would like to create a variable that is 30 days in the future based on $endtimefrom. What would be a good way?

Thank you.
User avatar
stereofrog
Forum Contributor
Posts: 386
Joined: Mon Dec 04, 2006 6:10 am

Post by stereofrog »

Code: Select all

$future = strtotime("+30 days", $now);
User avatar
SmokyBarnable
Forum Contributor
Posts: 105
Joined: Wed Nov 01, 2006 5:44 pm

Post by SmokyBarnable »

thanks!

:)
User avatar
Skara
Forum Regular
Posts: 703
Joined: Sat Mar 12, 2005 7:13 pm
Location: US

Post by Skara »

or

Code: Select all

$now = time();
$later = time() + 60 * 60 * 24 * 30;
seconds * minutes * hours * days
User avatar
dreamscape
Forum Commoner
Posts: 87
Joined: Wed Jun 08, 2005 10:06 am
Contact:

Post by dreamscape »

Skara wrote:or

Code: Select all

$now = time();
$later = time() + 60 * 60 * 24 * 30;
seconds * minutes * hours * days
But that is so ugly, and strtotime() makes code so much more readable :wink:
User avatar
mikeq
Forum Regular
Posts: 512
Joined: Fri May 03, 2002 3:33 am
Location: Edinburgh, Scotland

Post by mikeq »

You dont need the $now variable with strtotime

Code: Select all

$ThirtyDaysHence = strtotime("+30 days");
Post Reply