cgm225 Posted September 12, 2008 Share Posted September 12, 2008 I have a timestamp in the following format:: 0000-00-00 00:00:00 and I want to check it against the time() function and dermine if the timestamp is less than a minute old. I have been trying to do this without success. So for I have the following... if (empty($timestamp)) { $timestamp = 0; } else { $timestamp = strtotime($timestamp); } //New comments limited to every sixty seconds if((time() - $timestamp) < (60)) { $this->successfulSubmission = false; return false; } else { return true; } Any ideas what I am doing wrong? Link to comment https://forums.phpfreaks.com/topic/124006-comparing-timestamp-to-date/ Share on other sites More sharing options...
cgm225 Posted September 13, 2008 Author Share Posted September 13, 2008 bump Link to comment https://forums.phpfreaks.com/topic/124006-comparing-timestamp-to-date/#findComment-640425 Share on other sites More sharing options...
kenrbnsn Posted September 13, 2008 Share Posted September 13, 2008 What's happening now? How do you know it's not working. We need more details. How is this code snippet used? Ken Link to comment https://forums.phpfreaks.com/topic/124006-comparing-timestamp-to-date/#findComment-640427 Share on other sites More sharing options...
PFMaBiSmAd Posted September 13, 2008 Share Posted September 13, 2008 Where is your original timestamp coming from? If it is a database, it is much easier to just select records in the query that have a timestamp with the values you are looking for. What have you done to troubleshoot the problem? Post an actual value in $timestamp that you are passing to the code. Link to comment https://forums.phpfreaks.com/topic/124006-comparing-timestamp-to-date/#findComment-640430 Share on other sites More sharing options...
cgm225 Posted September 13, 2008 Author Share Posted September 13, 2008 I get the timestamp value from a database as follows: $query = 'SELECT id, ip_address, timestamp FROM comments WHERE ip_address = ? ORDER BY timestamp ASC'; $statement = $this->connection->prepare($query); $statement->bind_param('s', $this->ip); $statement->bind_result($id, $ip_address, $timestamp); $statement->execute(); $statement->fetch(); $statement->close(); Also, I have tried the following also to just see what the output looks like, and I get the following $timestamp = time(); echo (time() - $timestamp); //Output is 0 which makes sense ///////// $timestamp = '2008-08-25 20:48:48'; echo time(); //Output is 1221310409 echo (time() - $timestamp); //Output is 1221308401 echo (time() - strtotime($timestamp)); //Output is 1598681 So I am not sure what exactly I am doing wrong? Again, my overall goal is to find out if a timestamp is less than a minute old (to prevent a user from posting again). Thanks again for the help! Link to comment https://forums.phpfreaks.com/topic/124006-comparing-timestamp-to-date/#findComment-640437 Share on other sites More sharing options...
BlueSkyIS Posted September 13, 2008 Share Posted September 13, 2008 the last one is right. that's seconds. divide by 60 to get minutes echo (time() - strtotime($timestamp)); //Output is 1598681 Link to comment https://forums.phpfreaks.com/topic/124006-comparing-timestamp-to-date/#findComment-640448 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.