SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Evangelist
    Join Date
    Apr 2007
    Posts
    398
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Timestamp help please

    Hello,

    I'm trying to get my head around comparing two dates in a MYSQL query.

    Say I have a timestamp called out of a database

    PHP Code:
    $database_timestamp $row['database_timestamp']; 
    and I have a current timestamp
    PHP Code:
    $current_timestamp = ('Y-m-d H:i:s'strtotime('now')); //Now 
    How can I write a query to say if the $database_timestamp is last 10 minutes elapsed of the $current_timestamp then don't do something, else do do it.

    Just can't get my head around it

  2. #2
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,578
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Work with them as timestamps (number of seconds since January 1, 1970) rather than formatted strings, then it's just arithmetic.

    PHP Code:
    $database_timestamp strtotime($row['database_timestamp']);
    $minutes_difference = (time() - $database_timestamp) / 60
    But really you should just do it in your database query.

    Code:
    SELECT ... WHERE database_timestamp < DATE_SUB(CURRENT_TIMESTAMP, interval 10 minute)


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •