PDA

View Full Version : Resolved Looking for an addition



Dirt_Diver
01-09-2009, 02:41 AM
How do I add two hours to this code?


$date = date("Y-m-d");
$time = date("g+2:i a");

I tired this but it actually displays the time with a "+2" in the center of it.

$date = date("Y-m-d");
$time = date("g+2:i a")+2;

Nile
01-09-2009, 02:46 AM
I would just do something like:


<?php
$date = date("Y-m-d ");
$time = date("g:i a", strtotime("+2 hours"));
echo $date.$time;
?>

Dirt_Diver
01-09-2009, 02:48 AM
I also tired this but got a fatal error


date_default_timezone_set('America/New_York');

Nile
01-09-2009, 02:52 AM
I've made an edit to my post, look above.
When using date_default_timezone_set, you also have to include a _get below it.
[From what I understand]

Dirt_Diver
01-09-2009, 02:55 AM
Ahhh yes thanks again Buddy.

Nile
01-09-2009, 02:56 AM
Anytime, you could also use the mktime function if you wanted. ;)