1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Quick CURDATE question

Discussion in 'PHP' started by misohoni, May 10, 2014.

  1. #1
    I'd like to use CURDATE so that I can show content + 7 days ahead of the actual date.

    Something like this? (but of course this won't work):
    ORDER BY a.date_live > CURDATE(7)
    Code (markup):
    I think there's a where statement to be added someplace too?

    thanks guys
     
    misohoni, May 10, 2014 IP
  2. PoPSiCLe

    PoPSiCLe Notable Member

    Messages:
    2,517
    Likes Received:
    285
    Best Answers:
    90
    Trophy Points:
    275
    #2
    Use
    WHERE a.date_live > DATE_ADD(CURDATE() INTERVAL 7 DAY) ORDER BY a.date_live
    Code (markup):
    Not tested, but should work
     
    PoPSiCLe, May 10, 2014 IP
    misohoni likes this.
  3. deathshadow

    deathshadow Illustrious Member

    Messages:
    7,140
    Likes Received:
    1,123
    Best Answers:
    173
    Trophy Points:
    445
    #3
    I thought DATE_ADD choked on anything that wasn't a full ISO date, which is why you'd use NOW() instead of CURDATE()...

    Other than that, yeah. Use DATE_ADD with INTERVAL... though you also missed a comma.

      WHERE a.date_live > DATE_ADD(NOW(), INTERVAL 7 DAY)
      ORDER BY a.date_live
    Code (markup):
     
    deathshadow, May 10, 2014 IP
    misohoni and seotraining like this.
  4. seotraining

    seotraining Active Member

    Messages:
    511
    Likes Received:
    26
    Best Answers:
    0
    Trophy Points:
    70
    #4
    Those are some great answers.. not tested this yet, not sure if this is a good tip but you could maybe use
    DATE_SUB(NOW(), INTERVAL 7 DAY)
    Code (markup):
    the system needs show events to happen 7 days ahead.

    WHERE date_starts >= DATE_ADD(NOW(), INTERVAL 7 DAY)
    ORDER BY date_starts
    Code (markup):
     
    seotraining, May 10, 2014 IP
    misohoni likes this.
  5. misohoni

    misohoni Notable Member

    Messages:
    1,714
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    200
    #5
    Thanks guys all the answers worked for me
     
    misohoni, May 10, 2014 IP