How do I add 12 hours to NOW()

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Issa Fox

    #1

    How do I add 12 hours to NOW()

    The following code allows a list of seminars to display on a homepage:

    Code:
    $sql = 'SELECT ID,title,division,startdate,enddate,time,location 
                   FROM event 
                   WHERE category="1" AND startdate > NOW()
                   ORDER BY startdate, enddate 
                   LIMIT 4';
    The first seminar will only show up until the time of the conference. I would like for it to display for 12 hours after the conference occurs. How do I make that happen?
    Last edited by Atli; Oct 4 '10, 09:36 PM. Reason: Please use [code] tags when posting code.
  • dlite922
    Recognized Expert Top Contributor
    • Dec 2007
    • 1586

    #2
    Issa Fox, welcome to Bytes!

    In this instance you can do it with PHP and replace NOW() with a calculated time, but I suggest you go the MySQL route because it's quicker.

    http://dev.mysql.com/doc/refman/5.1/...ction_date-add

    like so: DATE_ADD(NOW(), INTERVAL 12 HOURS)

    Cheers,

    Dan

    Comment

    • HaLo2FrEeEk
      Contributor
      • Feb 2007
      • 404

      #3
      Or:

      strtotime("+12 hours")

      Should also work, and saves you from calling the now() function AND the date_add() function.

      Comment

      • dlite922
        Recognized Expert Top Contributor
        • Dec 2007
        • 1586

        #4
        There's only one way to settle this: Benchmarking.

        Somebody should create a 1,000,000 row table with a string and a random date 1979-Present. Then run +12 hour Select commands on a random number of records 1-n at a time using each of the methods.

        My bets are on MySQL.

        Cheers!

        Dan

        Comment

        Working...