Page 1 of 1
Which Time Function To Use
Posted: Mon Jan 11, 2010 3:15 am
by JakeJ
There seem to be several time functions out there and I'm not sure which will suit my needs best.
I need to add $months to a time stamp for now().
I need to output a future date $months from now.
Thanks!
Re: Which Time Function To Use
Posted: Mon Jan 11, 2010 3:17 am
by requinix
strtotime() converts an English string to a Unix timestamp.
Code: Select all
$months = 5;
$time = strtotime("+{$months} months");
echo date("Y-m-d H:i:s", $time);
Re: Which Time Function To Use
Posted: Mon Jan 11, 2010 3:37 am
by onion2k
JakeJ wrote:I need to add $months to a time stamp for now().
NOW() is a MySQL function. If you're doing this in MySQL, use DATE_ADD.
Re: Which Time Function To Use
Posted: Mon Jan 11, 2010 3:37 am
by pbs
I thing you need my sql function, so use:
Code: Select all
DATE_ADD( NOW( ) , INTERVAL 1 MONTH );
Re: Which Time Function To Use
Posted: Mon Jan 11, 2010 1:13 pm
by JakeJ
tasairis wrote:strtotime() converts an English string to a Unix timestamp.
Code: Select all
$months = 5;
$time = strtotime("+{$months} months");
echo date("Y-m-d H:i:s", $time);
That did it for me! Muchas Gracias!