Page 1 of 1

PHP Time Showing incorrect time

Posted: Sun May 10, 2009 11:20 am
by VarwigDude
Can anyone Tell me why when I run this code

Code: Select all

<?php
// a START time value
$end_time_and_date = time() + (7 * 24 * 60 * 60);
 
$current_time = time();
 
$diff = $end_time_and_date - $current_time;
 
$display_end_time_and_date = (date("F dS Y h:i:s A",$diff));
 
echo $display_end_time_and_date;
 
?>
 
The Output is "January 07th 1970 05:00:00 PM"
I am trying to get the differance from $current_time and $end_time_and_date

Thank You

Re: PHP Time Showing incorrect time

Posted: Sun May 10, 2009 3:44 pm
by Mark Baker
VarwigDude wrote:Can anyone Tell me why when I run this code

Code: Select all

<?php
The Output is "January 07th 1970 05:00:00 PM"
I am trying to get the differance from $current_time and $end_time_and_date
[/quote]
Because you're trying to display the result of the difference as an actual date/time.
The difference that you're calculating is the number of seconds in a week: treated as a full date/time, that gives one week from the PHP base date/time (January 1st 1970 ). The additional variance in hours is a timezone offset.