Any body know how to format date in php

Discussion in 'Programming' started by mumfry, Oct 30, 2011.

  1. #1
    hello

    am looking to get a result like this
    Oct 27

    from a date format that's like this
    2011-10-27 22:20:29

    how can i do this using good ole Php or is it at all possible

    any help would be greatly appreciated
    thanks :cool:
     
    Solved! View solution.
    mumfry, Oct 30, 2011 IP
  2. russonline

    russonline Member

    Messages:
    76
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #2
    http://php.net/manual/en/function.date.php , scroll down to example #4 to see similar solutions. You just need to get Month and day from date function.
     
    russonline, Oct 30, 2011 IP
  3. mumfry

    mumfry Active Member

    Messages:
    118
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #3
    hey russ thanx a bunch for the reply
    wasnt quite what i was looking for but...

    i was able to get it done by using the php mktime() function together with date function
    here it is in case any body else might need to do something like this... or even if there is someone who knows of a shorter more efficient way of doing it please let me know, cause i gotta admit this code is kinda messy but it got it done for me :D

    $added_date="2011-10-27 22:20:29";
    $added_ymd=substr($added_date,0,10);
    $added_ymd=explode("-",$added_ymd);
    $added_hms=substr($added_date,11);
    $added_hms=explode(":",$added_hms);
    echo(date("M-d-Y",mktime($added_hms[0],$added_hms[1],$added_hms[2],$added_ymd[1],$added_ymd[2],$added_ymd[0]))."<br />");
     
    mumfry, Oct 30, 2011 IP
  4. #4
    $date = date("M d", strtotime("2011-10-27 22:20:29"));
    PHP:
    Oct 27
    Code (markup):
     
    MIN BINARY, Oct 30, 2011 IP
  5. mumfry

    mumfry Active Member

    Messages:
    118
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #5
    wow min binary

    simply simple, simply brilliant...
    well done my friend
    thanx for this
    mind if i come to you for any php help in the future.

    thank you again
     
    mumfry, Oct 30, 2011 IP