Jump to content

Working with date and time...


Aureole

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

 

:)

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.