Web Analytics Made Easy -
StatCounter Seeing if a DATETIME value is over 24 hours ago? - CodingForum

Announcement

Collapse
No announcement yet.

Seeing if a DATETIME value is over 24 hours ago?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Seeing if a DATETIME value is over 24 hours ago?

    I need a if statement that checks to see if a datetime value is >= 24 hours ago.

    Here's what I need it for: if a user clicks a button the datetime would be updated in the database for that user. Only 24 hours after may that same user click that button again.

    Any suggestions?

  • #2
    Pull out of your database the time stamp and place it in a variable such as $date_time and use the code below.

    PHP Code:
    $flexibility 86400// 60 * 60 * 24 to get 86400 seconds which is 24 hours.
    if ($date_time time() - $flexibility )
    { echo 
    "You must wait 24 hours before pressing this button."; } 
    Notice: If you post a problem and it gets fixed, please remember to go back and place it as solved. ;)
    I always recommend the HEAD First series of books for learning a new coding language. ^_^

    Comment


    • #3
      This can be done entirely in MySQL using DATE_SUB():
      http://dev.mysql.com/doc/refman/5.5/...functions.html
      Code:
      SELECT *
      FROM `user`
      WHERE DATE_SUB( NOW(), INTERVAL 1 DAY ) >= `user_lastClick`
      Using this query, only those users who are allowed to re-click will be selected.

      Untested, but should work.
      ZCE

      Comment

      Working...
      X