Jump to content

Basic Question - Time left till date Unix TimeStamp wont work?


sillyman

Recommended Posts

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);

?>

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.