0

hi have my : regional format date like : 01-Iulie-2014 or 01-Decembrie-2015 and I want to convert it into: 2014-07-01 or 2015-12-01. I tried something like this,but with no result:

$mydate = date('Y-m-d', strtotime($this->input->post('pay_date')));

but strtotime returns me false

Is there a function to do this stuff ?

Attila Naghi
  • 2,535
  • 6
  • 37
  • 59

2 Answers2

0

strtotime() parses about any English textual datetime description into a Unix timestamp, so you could do, create an array of month names in your language and its equivalent english month name, and then use strtotime, as:

function custom_strtotime($your_date) { 
    //create month names as your_lang_month_name => english_month_name 
    $months_arr = array('Janvier'=>'jan',...,'Decembrie'=>'dec')
    return strtotime(strtr(strtolower($your_date), $months_arr)); 
}
echo custom_strtotime($some_date);
Sudhir Bastakoti
  • 99,167
  • 15
  • 158
  • 162
0

From http://php.net/manual/en/function.date.php:

To format dates in other languages, you should use the setlocale() and strftime() functions instead of date().