Jump to content

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


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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.