Timestamp questions

Discussion in 'PHP' started by getatune, Oct 9, 2010.

  1. #1
    Hey,

    Im using the current_timestamp in mysql for my time and I was wondering how can I make it check if its been 10 minutes yet in php?
     
    getatune, Oct 9, 2010 IP
  2. JoelLarson

    JoelLarson Peon

    Messages:
    61
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Here is a possible solution (that involves PHP and MySQL commands):

    <?php
    
    $link = mysql_connect('localhost', 'root', '');
    mysql_select_db('testing', $link);
    
    $sql = "SELECT UNIX_TIMESTAMP(`timestamp`) as `timestamp` FROM `posts` WHERE `id` = 1 LIMIT 0, 1";
    $query = mysql_query($sql);
    $result = mysql_fetch_object($query);
    
    if($result->timestamp <= time() - (60*10))
    {
    	echo '10 minutes has elapsed.';
    }
    Code (markup):
    My example database has ID (int 11) and timestamp (timestamp).

    Essentially if the current time - 10 minutes is greater than the timestamp, it executes the code.
     
    JoelLarson, Oct 9, 2010 IP