Hello, I have mysql field set to date and a date given of 2003-06-08. I want PHP to pull that and convert it to June 8, 2003.

Is there an easy way to do this?

Thanks!

    <?
    $dateArray = explode("-", $date)
    
    switch($dateArray[2]){
       case "01":
             echo "January";
             break;
       case "02":
             echo "February";
             break;
       //..... and so on 
    }
    echo " ".$dateArray[3].", ".$dateArray[1];
    

    Try something like that... dont know of any easier way off hand

    GL

      
      <? 
      function datetime_to_epoch($date) { 
      $break = explode(" ", $date); 
      $datebreak = explode("-", $break[0]);
      $time = explode(":", $break[1]);
      $epoch = date("U", mktime($time[0],$time[1],$time[2],$datebreak[1],$datebreak[2],$datebreak[0])); 
      $datetime = date("F jS, Y", mktime($time[0],$time[1],$time[2],$datebreak[1],$datebreak[2],$datebreak[0])); 
      
      } 
      ?> 
      

      F jS, Y formats to June 17th, 2003.

      www.php.net/date

        Easiest way to do this is to get mysql to return it in the format you want

        So

        SELECT DATE_FORMAT(fieldname,'%W %D %M %Y') as 'alias_name', 
        

        This way mysql does all the hard word and you don't need any of the other stuff. By putting the alias in there it makes it easy to refer to.

        HTH

        GM

          I personally do not use the MySQL date format. I simply store the date in the database as a BIGINT (using the UNIX timestamp.)

          This way I can simply feed that integer to PHP's built in date() function and format it any way i want.

          Chris

            Message for dinger

            Why take 2 steps to do what can be done in 1 ?

            Just a small question

            GM 😃

              Or it can be done with this simple function:

              date( " F j, Y", strtotime($date));

              Hope it helps you.

                Write a Reply...