public function convertDate($date, $from = null, $to = 'Y-m-d')
    {
        if (!$date) {
            return null;
        }
        if ($from === null) {
            $from = $this->app->getConfig('locale/date', null);
        }
        if ($from === null) {
            // no format configured, so use our best guess. Will work with Y-m-d
            $date = new DateTime($date);
        } else {
            $date = date_create_from_format($from, (string) $date);
        }
        if ($to === null) {
            $to = $this->app->getConfig('locale/date', 'Y-m-d');
        }

        if ($date === false) {
            throw $this->exception('Date format is not correct');
        }

        return date_format($date, $to);
    }
public function convertDate($date, $from = null, $to = 'Y-m-d')
    {
        if (!$date) {
            return null;
        }
        if ($from === null) {
            $from = $this->app->getConfig('locale/date', null);
        }
        if ($from === null) {
            // no format configured, so use our best guess. Will work with Y-m-d
            $date = new DateTime($date);
        } else {
            $date = date_create_from_format($from, (string) $date);
        }
        if ($to === null) {
            $to = $this->app->getConfig('locale/date', 'Y-m-d');
        }

        if ($date === false) {
            throw $this->exception('Date format is not correct');
        }

        return date_format($date, $to);
    }
public function convertDate ( $ date , $ from = null , $ to = 'Y-m-d' ) { if ( ! $ date ) { return null ; } if ( $ from === null ) { $ from = $ this -> app -> getConfig ( 'locale/date' , null ) ; } if ( $ from === null ) { // no format configured, so use our best guess. Will work with Y-m-d $ date = new DateTime ( $ date ) ; } else { $ date = date_create_from_format ( $ from , ( string ) $ date ) ; } if ( $ to === null ) { $ to = $ this -> app -> getConfig ( 'locale/date' , 'Y-m-d' ) ; } if ( $ date === false ) { throw $ this -> exception ( 'Date format is not correct' ) ; } return date_format ( $ date , $ to ) ; }
Convert date from one format to another.

@param string $date Date in string format
@param string $from Optional source format, or null to use locale/date from configuration
@param string $to Optional target format, or null to use locale/date from configuration

@return string|null
Convert date from one format to another .