SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    Apr 2005
    Posts
    86
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Convert string date to array format

    I am wondering how I would convert a string such as Jan 1 1980 12:00AM to an array like the following:
    Array (
    [m] => 1
    [d] => 1
    [Y] => 1980
    )

    The string above is just an example. In practise the month, date and year could be anything, but the time will always be 12:00AM. As the array shows I am not interested in keeping the time information, just in splitting the string to the correct array format.

    Do you know how to do that? Is there a PHP function that would do such a thing?

    thAnks.

  2. #2
    SitePoint Wizard silver trophy
    Join Date
    Mar 2006
    Posts
    6,132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $months = array(
        
    'Jan' => 1,
        
    'Feb' => 2,
        
    // etc...
    );
    list (
    $m$d$y) = explode(' '$foo);
    $array = array('m' => $months[$m], 'd' => $d'y' => $y); 
    edited.


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
  •