SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Zealot
    Join Date
    Apr 2004
    Location
    Somewhere in the Middle East
    Posts
    106
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Retrieving date from MySQL into PHP

    HI!

    I am selecting and echoing a datetime array called $creation_time stored in my MySQL database via PHP. The PHP script echoes it fine but I would prefer it just to echo the month and year. Currently it displays 2010-05-28 00:00:00 while I would like it to echo just May 2010.

    Any simple ways I can do this?

    PHP Code:
    $keyid $get['keyid'];

            
    $db = new Database(DB_CONF$log);
            
    $db->execute('
                SELECT article.title, article.author_name, article.summary, article.creation_time
                FROM article
                WHERE article.category_name = "' 
    $keyid '"
                ORDER BY creation_time ASC;'
    );
                
            
    $res $db->getAll();


            foreach (
    $res as $row) {
                
    $title $row['title'];
                
    $author_name $row['author_name'];
                
    $summary $row['summary'];
                
    $creation_time $row['creation_time'];
                
                
    $listofarticles .= "<p><b>$title</b> ($creation_time) <br />by $author_name <p> <i>$summary</i></p></p>";
            }

    echo 
    "$listofarticles"
    MANY THANKS!

    leao

  2. #2
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,747
    Mentioned
    65 Post(s)
    Tagged
    0 Thread(s)
    date('M Y',strtotime($creation_time));

  3. #3
    Non-Member
    Join Date
    May 2010
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    $creation_time = date('M Y',strtotime($creation_time));

  4. #4
    SitePoint Zealot
    Join Date
    Apr 2004
    Location
    Somewhere in the Middle East
    Posts
    106
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    brilliant!

  5. #5
    SitePoint Zealot
    Join Date
    Jun 2008
    Location
    Gloucestershire, UK
    Posts
    197
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Or you could use MySQL's DATE_FORMAT() function.

    Cheers,

    Jon


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •