Jump to content

unix timestamps


eon201

Recommended Posts

Hey,

 

Im doing a quick sum with unix timestamps within a loop to work out if the array is within my specified time frame, and if y or n then do something else.

 

Here is my code so far...

 

$timenow = time();

while($row = mysql_fetch_array( $result )) {

echo "Timenow = $timenow<br/><br/>";

echo $row['ip']. " -- ";
echo $row['url']. " -- ";
echo $row['date']. " -- ";

$ip[] = $row['ip'];
$url[] = $row['url'];
$date[] = $row['date'];

$timediff = $timenow - $date;

if ($timediff <='3600'){
echo "This one IS within an hours time difference comparitive to NOW<br/><br/>";
}
if ($timediff >'3600'){
echo "This one IS NOT within an hours time difference comparitive to NOW<br/><br/>";
}
}

 

For some reson im getting the error... Fatal error: Unsupported operand types for this line "$timediff = $timenow - $date;" ???

 

Why is this. It looks ok to me. Anyhelp would be appreciatted!

Link to comment
https://forums.phpfreaks.com/topic/77600-unix-timestamps/
Share on other sites

Variables in PHP are represented by a dollar sign followed by the name of the variable. The variable name is case-sensitive.

 

like nezbo did

$date = $row['date'];

 

Square brackets (from php manual)

An opening square bracket introduces a character class, terminated by a closing square bracket. A closing square bracket on its own is not special. If a closing square bracket is required as a member of the class, it should be the first data character in the class (after an initial circumflex, if present) or escaped with a backslash.

 

Link to comment
https://forums.phpfreaks.com/topic/77600-unix-timestamps/#findComment-392790
Share on other sites

Hey cool. You fixed it thanks!!!

 

But for the future... Whats the deal with the square brackets?? What difference does that make? ???

 

Thanks Eon201

 

adding the [] makes it an array, in which case you cant subtract whole arrays at a time (you'd have to do it one value at a time) or arrays from strings, et cetera.

 

$timediff = $timenow - $date[0];

 

Probably would have worked as well if you wanted it to be an array

Link to comment
https://forums.phpfreaks.com/topic/77600-unix-timestamps/#findComment-392795
Share on other sites

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.