Select results within timeframe

Discussion in 'PHP' started by guruguy, Aug 15, 2008.

  1. #1
    Hi,

    Can someone give me ideas on how to structure a query to select results that are over 30 days but less than 60 days old, using the timestamp on the record? I have never played around much with date and time so I am quite clueless as where to begin. Thanks
     
    guruguy, Aug 15, 2008 IP
  2. EricBruggema

    EricBruggema Well-Known Member

    Messages:
    1,740
    Likes Received:
    28
    Best Answers:
    13
    Trophy Points:
    175
    #2
    where unix_timestamp(`datefield`) > (unix_timestamp(CURDATE()) - 60*60*24*30)
    AND unix_timestamp(`datefield`) < (unix_timestamp(CURDATE()) + 60*60*24*30)

    This is the easy way... but there are alot of more easy ways :p

    Haven't tested it :)
     
    EricBruggema, Aug 16, 2008 IP
  3. guruguy

    guruguy Active Member

    Messages:
    553
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    60
    #3
    Thanks, that looks good. When I get a chance to test it I'll tell you how it goes.

    Edit: Over looking again, it seems that it will select records that are less than 30 days old and not further than 30 days into the future? I may have gone cross eyed :D
     
    guruguy, Aug 16, 2008 IP