sillyman Posted March 27, 2010 Share Posted March 27, 2010 I am trying to compare two Unix TimeStamps, one current date and one future date to see the time left, but I get a date from 1970. <?php //Current Server Time in Unix TimeStamp $today = date(U); echo "Current Server Time ".$today; echo "<br />"; //February 10, 2011, 12:00 am in Unix TimeStamp $target = (1297296000) ; echo $target; echo "<br />"; //echo date('F j, Y, g:i a',$target); //echo "<br />"; //Compare both timestamps $difference =($target-$today) ; echo $difference; echo "<br />"; //Covert time into more readable format echo date('F j, Y, g:i a',$difference); ?> Quote Link to comment https://forums.phpfreaks.com/topic/196722-basic-question-time-left-till-date-unix-timestamp-wont-work/ Share on other sites More sharing options...
greatstar00 Posted March 27, 2010 Share Posted March 27, 2010 as you said, time left not the date, they are different you should say, 10months 20 days 20 hours not NOV 20, 1970 (nor March 26, 2010) so, you have to define your own function floor($difference /86400) . ' days '. floor(($difference % 86400)/3600). ' hours '. floor((($difference % 86400)%3600)/60) . ' minutes '. floor(((($difference % 86400)%3600)%60)) . ' seconds.' <?php //Current Server Time in Unix TimeStamp $today = date(U); echo "Current Server Time ".$today; echo "<br />"; //February 10, 2011, 12:00 am in Unix TimeStamp $target = (1297296000) ; echo $target; echo "<br />"; //echo date('F j, Y, g:i a',$target); //echo "<br />"; //Compare both timestamps $difference =($target-$today) ; echo $difference; echo "<br />"; //Covert time into more readable format //echo date('F j, Y, g:i a',$difference).'<br />'; echo floor($difference / 86400) . ' days '. floor(($difference % 86400)/3600). ' hours '. floor((($difference % 86400)%3600)/60) . ' minutes '. (((($difference % 86400)%3600)%60)) . ' seconds.'; you can check this too http://www.php.net/manual/en/function.date-diff.php Quote Link to comment https://forums.phpfreaks.com/topic/196722-basic-question-time-left-till-date-unix-timestamp-wont-work/#findComment-1032778 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.