Convert a date in french format in a mysql datetime format

How about?

date("Y-m-d H:i:s", strtotime($datetime));

Ah, yes, I see the problem. strtotime only converts english text (emphasis mine):

The function expects to be given a string containing an English date format and will try to parse that format into a Unix timestamp

Your best bet is probably going to be preg_match for your specific format, as there doesn't seem to be any locale-specific functions that will convert things like the month name.


I just wrote this to convert a french date in day/months/year to english format and next to MYSQL. Assuming original date is separated by a "/" slash

    private function dateToMySQL($date){
        $tabDate = explode('/' , $date);
        $date  = $tabDate[2].'-'.$tabDate[1].'-'.$tabDate[0];
        $date = date( 'Y-m-d H:i:s', strtotime($date) );
        return $date;
    }

It's pretty basic and warn if missing numbers like day.

Tags:

Datetime

Php

Date