Results 1 to 6 of 6

Thread: reformat date brought bad results

  1. #1
    Join Date
    Apr 2010
    Location
    University of Illinois
    Posts
    86
    Thanks
    13
    Thanked 2 Times in 2 Posts

    Default reformat date brought bad results

    The date in my database looks like 2010-08-18
    I want to format the date to make it look like August 18, 2010

    Code:
    $result = mysql_query("SELECT * FROM webcalendar_events WHERE dt >= now() ORDER BY dt")
    or die(mysql_error());  
    
    while($row = mysql_fetch_array($result, MYSQL_ASSOC))
    {
     echo"<p>Name: {$row['dt']}<br />".
     "Decription: {$row['description']}</p>";
    Can anyone tell me how I can change my code to get the correct format. After looking at the online php manual I got some real bad results...not posting the bad code or you would laugh.
    Last edited by I am Abby; 08-17-2010 at 03:13 PM.

  2. #2
    Join Date
    Apr 2010
    Location
    University of Illinois
    Posts
    86
    Thanks
    13
    Thanked 2 Times in 2 Posts

    Default

    Code:
    // Retrieve all the data from the "webcalendar_events" table
    $result = mysql_query("SELECT * FROM webcalendar_events WHERE dt >= now() AND color='ffff00' ORDER BY dt")
    or die(mysql_error());  
    
    while($row = mysql_fetch_array($result, MYSQL_ASSOC))
    {
     echo"<p>Name: {$row['dt']}<br />".
     "Decription: {$row['description']}</p>";
    }
    So first I want to split the date

    Code:
     list($year, $month, $day) = split('[/.-]', {$row['dt']};
    But I get a message that there was an unexpected "{". If I remove the pair, it doesn't like the ";".
    Help!

  3. #3
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    in your specific example above:
    Code:
    list($year, $month, $day) = split('[/.-]', {$row['dt']});
    I didn't look at anything else yet, though.

  4. #4
    Join Date
    Apr 2010
    Location
    University of Illinois
    Posts
    86
    Thanks
    13
    Thanked 2 Times in 2 Posts

    Default

    How could I mis that?
    thanks.

  5. #5
    Join Date
    Apr 2010
    Location
    University of Illinois
    Posts
    86
    Thanks
    13
    Thanked 2 Times in 2 Posts

    Default

    Code:
    {
     list($year, $month, $day) = split('[/.-]', $row['dt']);
     $month = date(M);
     echo "<p><strong>{$month} {$day}, {$year}</strong><br />".
     "Decription: {$row['description']}</p>";
    }
    This code makes all the months the same as the first one.
    So I tried changing the code to
    Code:
    {
     list($year, $month, $day) = split('[/.-]', $row['dt']);
     echo "<p><strong>{$month = date(M)} {$day}, {$year}</strong><br />".
     "Decription: {$row['description']}</p>";
    }
    which it did not like at all.

  6. #6
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    is this
    PHP Code:
     list($year$month$day) = split('[/.-]'$row['dt']);
     echo 
    "<p><strong>{$month} {$day}{$year}</strong><br />".
     
    "Decription: {$row['description']}</p>"
    giving you what you want, with the exception that the month is still numeric (e.g., "8" instead of "August")?

    If so, add an array of all the months and use it to convert your $month:
    PHP Code:
     $monthnames = array(
        
    "1"=>"January",
        
    "2"=>"February"
        
    //etc
     
    );

     list(
    $year$month$day) = split('[/.-]'$row['dt']);
     
    $month $monthnames[$month];
     echo 
    "<p><strong>{$month} {$day}{$year}</strong><br />".
     
    "Decription: {$row['description']}</p>"

  7. The Following User Says Thank You to traq For This Useful Post:

    I am Abby (08-17-2010)

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
  •