Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,502
    Thanks
    8
    Thanked 1,089 Times in 1,080 Posts

    Date MM-DD-YYYY ==> 24th June 1983

    Converts a date in the format of: YYYY-MM-DD
    to a format of (for example): 24th June 1983

    Copy and Paste the function into your script.
    Make the function call as shown in the example.

    NOTE: You can convert any combination of date format
    by altering the "list" line.

    Example:
    YYYY-MM-DD ...
    list ($yr,$mn, $dy) = split ('-', $dt);

    MM-DD-YYYY ...
    list ($mn,$dy, $yr) = split ('-', $dt);


    Code:
    <?php
    $date="1983-06-24";
    echo pretty_date($date);
    
    
    function pretty_date($dt){
    list ($yr,$mn, $dy) = split ('-', $dt);
    $months = array(1 => 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');
    $da=intval($dy);
    $x="th";
    if(($da == 1)||($da == 21)||($da == 31)){$x="st";}
    if(($da == 2)||($da == 22)){$x="nd";}
    if(($da == 3)||($da == 23)){$x="rd";}
    $pd=$da.$x." ".$months[intval($mn)]." ".$yr;
    return $pd;
    }
    
    ?>
    Last edited by mlseim; 09-06-2006 at 02:37 PM. Reason: I typed the Thread Title wrong.

  • #2
    Senior Coder
    Join Date
    Aug 2003
    Location
    One step ahead of you.
    Posts
    2,815
    Thanks
    0
    Thanked 3 Times in 3 Posts
    Why not just:
    PHP Code:
    <?php
    $date 
    '2006-09-06';
    print 
    date('jS F Y'strtotime($date));
    ?>
    I'm not sure if this was any help, but I hope it didn't make you stupider.

    Experience is something you get just after you really need it.
    PHP Installation Guide Feedback welcome.

  • #3
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,502
    Thanks
    8
    Thanked 1,089 Times in 1,080 Posts
    You're right, I just saw that.
    I couldn't get it to work until I saw your example.

  • #4
    Super Moderator guelphdad's Avatar
    Join Date
    Mar 2006
    Location
    St. Catharines, Ontario Canada
    Posts
    2,634
    Thanks
    4
    Thanked 148 Times in 139 Posts
    and if your data is in a database then use the database function (like DATE_FORMAT in mysql) to format your dates.


  •  

    Posting Permissions

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