Simple PHP script help, if/else/timestamps/ less than / bit-shift
I am trying to make a timestamp function that checks which displays a time if it has been less than 24 hours and a date if it has been more. If anybody knows of a prebuilt way to do this please let me know.
Anyways, I've started with this simple php which is suppose to return a number less than 86400 if $temprow1 or 2 are less than 86400 seconds from now, or echo full if it has been over a day. This code outputs both as numbers, which it should not. Can somebody please help me figure out what's wrong. Thanks!
$temprow1 = 1278867245;
$temprow2 = 1258567245;
$tempvar008 = time()-$temprow1;
$tempvar009 = time()-$temprow2;
if($tempvar008 << 86400){echo $tempvar008;}else{echo 'full';}
echo '<br>';
if($tempvar009 << 86400){echo 开发者_C百科$tempvar009;}else{echo 'full';}
You use a single <
for less-than comparisons. <<
is for bit-shifting.
I'm not sure what the <<
is about in the context of an if, but try this:
$temprow1 = 1278867245;
$temprow2 = 1258567245;
$tempvar008 = time()-$temprow1;
$tempvar009 = time()-$temprow2;
if($tempvar008 < 86400){echo $tempvar008;}else{echo 'full';}
echo '</br>';
if($tempvar009 < 86400){echo $tempvar009;}else{echo 'full';}
$stamp1 = 1234567890; $stamp2 = 1234567891; $stampd = $stamp2 - $stamp1; if ($stampd < 86400) // code for showing time difference else // code for showing date difference
To continue using your code instead, please replace <<
with <
.
精彩评论