private function createDateTimeFromStr($dateString, $ignoreErrors = false)
    {
        if((!isset($dateString) || trim($dateString) === '')) return null;
        
        $regex = '/'
            . "(\d{4})(\d{2})(\d{2})?"     // YYYYMMDD             1,2,3
            . "(?:(\d{2})(\d{2})(\d{2}))?" // HHMMSS   - optional  4,5,6
            . "(?:\.(\d{3}))?"             // .XXX     - optional  7
            . "(?:\[(-?\d+)\:(\w{3}\]))?"  // [-n:TZ]  - optional  8,9
            . '/';

        if (preg_match($regex, $dateString, $matches)) {
            $year = (int)$matches[1];
            $month = (int)$matches[2];
            $day = (int)$matches[3];
            $hour = isset($matches[4]) ? $matches[4] : 0;
            $min = isset($matches[5]) ? $matches[5] : 0;
            $sec = isset($matches[6]) ? $matches[6] : 0;

            $format = $year . '-' . $month . '-' . $day . ' ' . $hour . ':' . $min . ':' . $sec;

            try {
                return new \DateTime($format);
            } catch (\Exception $e) {
                if ($ignoreErrors) {
                    return null;
                }

                throw $e;
            }
        }

        throw new \RuntimeException('Failed to initialize DateTime for string: ' . $dateString);
    }
private function createDateTimeFromStr($dateString, $ignoreErrors = false)
    {
        if((!isset($dateString) || trim($dateString) === '')) return null;
        
        $regex = '/'
            . "(\d{4})(\d{2})(\d{2})?"     // YYYYMMDD             1,2,3
            . "(?:(\d{2})(\d{2})(\d{2}))?" // HHMMSS   - optional  4,5,6
            . "(?:\.(\d{3}))?"             // .XXX     - optional  7
            . "(?:\[(-?\d+)\:(\w{3}\]))?"  // [-n:TZ]  - optional  8,9
            . '/';

        if (preg_match($regex, $dateString, $matches)) {
            $year = (int)$matches[1];
            $month = (int)$matches[2];
            $day = (int)$matches[3];
            $hour = isset($matches[4]) ? $matches[4] : 0;
            $min = isset($matches[5]) ? $matches[5] : 0;
            $sec = isset($matches[6]) ? $matches[6] : 0;

            $format = $year . '-' . $month . '-' . $day . ' ' . $hour . ':' . $min . ':' . $sec;

            try {
                return new \DateTime($format);
            } catch (\Exception $e) {
                if ($ignoreErrors) {
                    return null;
                }

                throw $e;
            }
        }

        throw new \RuntimeException('Failed to initialize DateTime for string: ' . $dateString);
    }
private function createDateTimeFromStr ( $ dateString , $ ignoreErrors = false ) { if ( ( ! isset ( $ dateString ) || trim ( $ dateString ) === '' ) ) return null ; $ regex = '/' . "(\d{4})(\d{2})(\d{2})?" // YYYYMMDD             1,2,3 . "(?:(\d{2})(\d{2})(\d{2}))?" // HHMMSS   - optional  4,5,6 . "(?:\.(\d{3}))?" // .XXX     - optional  7 . "(?:\[(-?\d+)\:(\w{3}\]))?" // [-n:TZ]  - optional  8,9 . '/' ; if ( preg_match ( $ regex , $ dateString , $ matches ) ) { $ year = ( int ) $ matches [ 1 ] ; $ month = ( int ) $ matches [ 2 ] ; $ day = ( int ) $ matches [ 3 ] ; $ hour = isset ( $ matches [ 4 ] ) ? $ matches [ 4 ] : 0 ; $ min = isset ( $ matches [ 5 ] ) ? $ matches [ 5 ] : 0 ; $ sec = isset ( $ matches [ 6 ] ) ? $ matches [ 6 ] : 0 ; $ format = $ year . '-' . $ month . '-' . $ day . ' ' . $ hour . ':' . $ min . ':' . $ sec ; try { return new \ DateTime ( $ format ) ; } catch ( \ Exception $ e ) { if ( $ ignoreErrors ) { return null ; } throw $ e ; } } throw new \ RuntimeException ( 'Failed to initialize DateTime for string: ' . $ dateString ) ; }
Create a DateTime object from a valid OFX date format

Supports:
YYYYMMDDHHMMSS.XXX[gmt offset:tz name]
YYYYMMDDHHMMSS.XXX
YYYYMMDDHHMMSS
YYYYMMDD

@param  string $dateString
@param  boolean $ignoreErrors
@return \DateTime $dateString
@throws \Exception
Create a DateTime object from a valid OFX date format