php string to date conversion?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nirmalsingh
    New Member
    • Sep 2006
    • 218

    php string to date conversion?

    i just want to convert 2007-04-09 as 09-April-2007. how to do this?? thanx in advance.
  • dzuse
    New Member
    • Apr 2007
    • 2

    #2
    Originally posted by nirmalsingh
    i just want to convert 2007-04-09 as 09-April-2007. how to do this?? thanx in advance.
    I have one way how to do it, its long but for me it works ;)
    i hope it will work for u!
    input is 2007-04-09 and output is 09-April-2007
    php code is [php]<?php
    $date = "2007-04-09";
    $explodedate = explode("-", $date);
    $year = $explodedate[0];
    $month = $explodedate[1];
    $day = $explodedate[2];
    if ($month == 01) { $month1 = 'Jan'; }
    if ($month == 02) { $month1 = 'Feb'; }
    if ($month == 03) { $month1 = 'Mar'; }
    if ($month == 04) { $month1 = 'April'; }
    if ($month == 05) { $month1 = 'may'; }
    if ($month == 06) { $month1 = 'Jun'; }
    if ($month == 07) { $month1 = 'Jul'; }
    if ($month == 08) { $month1 = 'Aug'; }
    if ($month == 09) { $month1 = 'Sep'; }
    if ($month == 10) { $month1 = 'Oct'; }
    if ($month == 11) { $month1 = 'Nov'; }
    if ($month == 12) { $month1 = 'Dec'; }
    echo $day."-".$month1."-".$year;
    ?>[/php]

    Please encode any code within the appropriate code tags, See the Posting guidelines before you continue posting in this forum - moderator
    Last edited by ronverdonk; Feb 28 '08, 01:36 PM. Reason: code within tags

    Comment

    • fluxcapacitor
      New Member
      • Mar 2007
      • 4

      #3
      this might work a little faster[php]function buildDate( &$date )
      {
      $explodedate = explode( "-", $date );
      $year = $explodedate[0];
      $month = $explodedate[1];
      $day = $explodedate[2];

      $months = array( '01' => 'Jan' , '02' => 'Feb' , '03' => 'Mar' , '04' => 'April' , '05' => 'May' , '06' => 'June' , '07' => 'July' , '08' => 'Aug' , '09' => 'Sept' , '10' => 'Oct' , '11' => 'Nov' , '12' => 'Dec' );

      foreach( $months as $key => $value ){
      if ( $key == $month ){
      $month = $value;
      break;
      }
      }

      echo $day.'-'.$month.'-'.$year;
      }[/php]

      Please encode any code within the appropriate code tags, See the Posting guidelines before you continue posting in this forum - moderator
      Last edited by ronverdonk; Feb 28 '08, 01:36 PM. Reason: code within tags

      Comment

      • ronverdonk
        Recognized Expert Specialist
        • Jul 2006
        • 4259

        #4
        Originally posted by nirmalsingh
        i just want to convert 2007-04-09 as 09-April-2007. how to do this?? thanx in advance.
        The fastest of them all, using the most simple solution using 2 PHP commands:[php]<?php
        echo date('j-F-Y',strtotime('2 007-04-09'));
        ?>[/php]Ronald

        Comment

        Working...