-3

i have a datetime format like this:

string '22 March 2014 - 15:48'

Now i want to change this format to "22/03/2014 - 15:48" to insert it into database with datatype is datetime. I appreciate your help. Thank you.

2 Answers2

0

try

date('d/m/y - H:i' ,strtotime(str_replace('-','','22 March 2014 - 15:48')));

Mark Richards
  • 434
  • 1
  • 8
  • 24
  • 1
    I don't think this is a very good solution. Why use a work around when there are perfectly valid solutions like [`DateTime::createFromFormat()`](http://in3.php.net/manual/en/datetime.createfromformat.php#refsect1-datetime.createfromformat-examples) available? – Amal Murali Mar 22 '14 at 09:25
0

Please Try This :-

$full_date= "22 March 2014 - 15:48";
  $date_array=explode("-",$full_date);
  $date=explode(" ",$date_array[0]);
  switch($date[1])
  {
    case "January": $month="01";
                    break;
    case "February": $month="02";
                    break;
    case "March": $month="03";
                    break;
    case "April": $month="04";
                    break;
    case "May": $month="05";
                    break;
    case "June": $month="06";
                    break;
    case "July": $month="07";
                    break;
    case "August": $month="08";
                    break;
    case "September": $month="09";
                    break;
    case "October": $month="10";
                    break;
    case "November": $month="11";
                    break;
    case "December": $month="12";
                    break;
  }

  $new_format=$date[0]."/".$month."/".$date[2]." - ".$date_array[1];
  echo $new_format;
Kushal Suthar
  • 423
  • 6
  • 21