src/Subjects/I18n/SimpleDateConverter.php
/**
     * Converts the passed date into a Magento 2 compatible date format.
     *
     * @param string $date   The date to convert
     * @param string $format The date format to convert to
     *
     * @return string|null The converted date
     */
Converts the passed date into a Magento 2 compatible date format.
@param string $date   The date to convert
@param string $format The date format to convert to

@return string|null The converted date
Converts the passed date into a Magento 2 compatible date format . @param string $date The date to convert @param string $format The date format to convert to @return string|null The converted date
public function convert($date, $format = 'Y-m-d H:i:s')
    {
        if (empty($date)) {
            return null;
        }
        if ($dateTime = \DateTime::createFromFormat($this->getDateConverterConfiguration()->getSourceDateFormat(), $date)) {
            return $dateTime->format($format);
        }
        try {
            return (new \DateTime($date))->format($format);
        } catch (\Exception $e) {
        }
        return null;
    }
public function convert ( $ date , $ format = 'Y-m-d H:i:s' ) { if ( empty ( $ date ) ) { return null ; } if ( $ dateTime = \ DateTime :: createFromFormat ( $ this -> getDateConverterConfiguration ( ) -> getSourceDateFormat ( ) , $ date ) ) { return $ dateTime -> format ( $ format ) ; } try { return ( new \ DateTime ( $ date ) ) -> format ( $ format ) ; } catch ( \ Exception $ e ) { } return null ; }
Converts the passed date into a Magento 2 compatible date format.
Converts the passed date into a Magento 2 compatible date format .
// only empty date will check otherwise we get "today" as date // create a DateTime instance from the passed value // if the date is not in configured format, // try to convert it using the default format // catch, if the date doesn't has the default date format // return NULL, if the passed value is NOT a valid date