Page 1 of 1

Date add problem

Posted: Mon Sep 12, 2011 4:32 pm
by daijames
Hi bit of a novice here I need the correct syntax for a date problem
my server is 5 hours behind, thats not a problem, but for my clients I need to show a date + 5 hours and a date +17hours as there is a 12 hour waiting period
I can do this if the date is now by using

Code: Select all

<?php echo date('l jS F Y H:i', strtotime('+17 hour')) ."\n"; ?>
But if I try to do a calculation on a variable I just keep getting errors can anyone give me the correct code please

I need to add 17 hours to:

Code: Select all

<?php
$date = date("l jS F Y H:i", strtotime($f4));
echo $date;
?>
Thanks

Re: Date add problem

Posted: Mon Sep 12, 2011 5:37 pm
by greip
strtotime() returns the time in seconds, so you need to add 17 * 60 * 60 to the value returned by that function.

Re: Date add problem

Posted: Mon Sep 12, 2011 7:06 pm
by daijames
so can you give me the correct fsyntax is it?

Code: Select all

<?php
 $date = date("l jS F Y H:i", strtotime($f4+17*60*60));
 echo $date;
 ?>

Re: Date add problem

Posted: Mon Sep 12, 2011 8:04 pm
by greip

Code: Select all

$date = date("l jS F Y H:i", strtotime($f4) + 17*60*60 );
should do it.

Re: Date add problem

Posted: Tue Sep 13, 2011 12:33 am
by daijames
purrfik thanks