Sort query by date created but only display the month

Discussion in 'PHP' started by mnymkr, Dec 22, 2006.

  1. #1
    I am working on a Joomla component for a story writing contest. I need the content sorted by month.

    I am not a complete idiot and I can sort the query by date created.

    2006-10-25 22:40:47


    However I need the results displayed as follows

    October 2006 (non linkable)
    -Story 1
    -Story 2
    -Sotry 3

    November 2006
    -story 1
    -story 2

    is this possible?

    The idea is that I will not have to recreate this every month.
     
    mnymkr, Dec 22, 2006 IP
  2. Pierre Monteux

    Pierre Monteux Peon

    Messages:
    63
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Yea its possible. If the date is in the format

    $date="2006-10-25 22:40:47";

    use $year=(explode('-',$date,2); //2 too keep only 2 pieces

    output of $year['0']=2006
    output of $year['1']=10-25 22:40:47

    just keep doing this and you'll get things how you need.
     
    Pierre Monteux, Dec 22, 2006 IP
  3. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #3
    To actually format the date output you should also be able to use.

    
    $date="2006-10-25 22:40:47";
    
    $output = date('F, Y', strtotime($date));
    //should return 'October, 2006'
    
    PHP:
     
    jestep, Dec 23, 2006 IP