Date add problem

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
daijames
Forum Newbie
Posts: 10
Joined: Mon Sep 12, 2011 3:50 pm

Date add problem

Post 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
greip
Forum Commoner
Posts: 39
Joined: Tue Aug 23, 2011 8:23 am
Location: Oslo, Norway

Re: Date add problem

Post by greip »

strtotime() returns the time in seconds, so you need to add 17 * 60 * 60 to the value returned by that function.
daijames
Forum Newbie
Posts: 10
Joined: Mon Sep 12, 2011 3:50 pm

Re: Date add problem

Post 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;
 ?>
greip
Forum Commoner
Posts: 39
Joined: Tue Aug 23, 2011 8:23 am
Location: Oslo, Norway

Re: Date add problem

Post by greip »

Code: Select all

$date = date("l jS F Y H:i", strtotime($f4) + 17*60*60 );
should do it.
daijames
Forum Newbie
Posts: 10
Joined: Mon Sep 12, 2011 3:50 pm

Re: Date add problem

Post by daijames »

purrfik thanks
Post Reply