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 Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #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 Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,998
    Best Answers:
    253
    Trophy Points:
    515
    #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,717
    Likes Received:
    32
    Best Answers:
    0
    Trophy Points:
    200
    #5
    Thanks guys all the answers worked for me
     
    misohoni, May 10, 2014 IP