Aureole Posted October 8, 2007 Share Posted October 8, 2007 I'm only just starting now to learn how to use date and time... What I'm trying to do is get a timestamp from the database then get the current time then what I want to do is compare the two to see if it is less than x minutes ago but I don't know how to compare timestamps, any tips/pointers? Link to comment https://forums.phpfreaks.com/topic/72296-working-with-date-and-time/ Share on other sites More sharing options...
Aureole Posted October 8, 2007 Author Share Posted October 8, 2007 Here's some playing around I did just experimenting (I have yet to test it)... do I have the genereal idea? <?php $query = "SELECT * FROM `replies` WHERE reply_parent_id='".$_GET['id']."' ORDER BY reply_id LIMIT 1 DESC"; $result = mysql_query($result); while($row = mysql_fetch_assoc($result)) { $lastposttimestamp = $row['reply_timestamp']; } $hmm = $replytimestamp - $lastposttimestamp; if($hmm < 30) { die('You must wait at least 30 seconds before adding another reply.'); exit; } ?> Link to comment https://forums.phpfreaks.com/topic/72296-working-with-date-and-time/#findComment-364544 Share on other sites More sharing options...
Aureole Posted October 8, 2007 Author Share Posted October 8, 2007 @ my own mistake > $result = mysql_query($result) ... Anyway I got it working, if anyone is interested here's how I did it: <?php $query = "SELECT * FROM `replies` WHERE reply_parent_id='".$_GET['id']."' ORDER BY `reply_id` DESC LIMIT 1"; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_assoc($result)) { $lastpost_timestamp = $row['reply_timestamp']; $lastpost_author_id = $row['author_id']; } if($lastpost_author_id == $_SESSION['mem_id']) { $reply_timestamp = time(); $seconds_since_last_reply = $reply_timestamp - $lastpost_timestamp; if($seconds_since_last_reply < 30) { die('You must wait at least 30 seconds before adding another reply.'); } else { // Query... } else { // Query... } ?> Link to comment https://forums.phpfreaks.com/topic/72296-working-with-date-and-time/#findComment-364562 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.