Jump to content

Recommended Posts

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

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;
}
?>

;D @ 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...
}
?>

 

:)

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.