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
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
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
Share on other sites

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.