Select time frame

Discussion in 'PHP' started by Fracisc, Feb 24, 2012.

  1. #1
    I have the time as 1329978937.
    How do I select from mysql each entry added this month?
     
    Fracisc, Feb 24, 2012 IP
  2. ker

    ker Peon

    Messages:
    97
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    0
    #2
    Hi, this is how to convert that time to mysql timestamp:
    
    strftime('%Y-%m-%d %H:%M:%S', $unix_timestamp);
    
    PHP:
    To get current month use:

    
    strftime('%Y-%m', $unix_timestamp);
    
    PHP:
     
    ker, Feb 24, 2012 IP
  3. Fracisc

    Fracisc Well-Known Member

    Messages:
    3,670
    Likes Received:
    10
    Best Answers:
    1
    Trophy Points:
    195
    #3
    I know how to change before echoing but how do I tell to mysql that I need to select all the entries added this month?
     
    Fracisc, Feb 24, 2012 IP
  4. Fracisc

    Fracisc Well-Known Member

    Messages:
    3,670
    Likes Received:
    10
    Best Answers:
    1
    Trophy Points:
    195
    #4
    Okay.. this works..


    SELECT 
      FROM_UNIXTIME(date, '%M') AS month
    FROM
     PSW_members
    WHERE
      FROM_UNIXTIME(date, '%M') = 'February';
    Code (markup):
     
    Fracisc, Feb 24, 2012 IP
  5. ker

    ker Peon

    Messages:
    97
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    0
    #5
    But that is not universal. Try this:
      FROM_UNIXTIME(date, '%M') AS month
    FROM
     PSW_members
    WHERE
     month = FROM_UNIXTIME(NOW() + 0, '%M');
    Code (markup):
     
    ker, Feb 25, 2012 IP
  6. Fracisc

    Fracisc Well-Known Member

    Messages:
    3,670
    Likes Received:
    10
    Best Answers:
    1
    Trophy Points:
    195
    #6
    I had it like this:

    WHERE FROM_UNIXTIME(time, '%M') = '".date("M")."'
     
    Fracisc, Feb 25, 2012 IP
  7. ker

    ker Peon

    Messages:
    97
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    0
    #7
    oh, then ok
     
    ker, Feb 25, 2012 IP