PHP Time Showing incorrect time

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
VarwigDude
Forum Newbie
Posts: 12
Joined: Tue Mar 31, 2009 8:08 pm

PHP Time Showing incorrect time

Post 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
Last edited by Benjamin on Sun May 10, 2009 12:43 pm, edited 1 time in total.
Reason: Changed code type from text to php.
Mark Baker
Forum Regular
Posts: 710
Joined: Thu Oct 30, 2008 6:24 pm

Re: PHP Time Showing incorrect time

Post 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.
Post Reply