Parses a date to Y-m-d

@param string $date   Date string
@param string $format Expected date $format (defaults to DATE_FORMAT)
@param string $output Iutput format (defaults to Y-m-d)

@return string On success
@return null   On failure
185466
protected static function parseDate(
        string $date,
        string $format = null,
        string $output = null
    ) {
        $d = \DateTime::createFromFormat($format ?? static::DATE_FORMAT, $date);
        return ($d ? $d->format($output ?? 'Y-m-d') : null);
    }
261818
private function parseDates($data, $format)
    {
        foreach ($data as $key => $entry) {
            $data[$key]['date'] = $data[$key]['date']->format($format);
        }

        return $data;
    }
824726
public static function dateSQL($date, $format = 'd-m-Y')
    {
        if (empty($date)) {
            return null;
        }

        $obj = DateTime::createFromFormat('Y-m-d H:i:s', $date);
        if (empty($obj)) {
            return null;
        }

        return $obj->format($format);
    }
370655
static public function checkDate(string $date, string $format = 'Y-m-d'): bool
    {
        $d = DateTime::createFromFormat($format, $date);

        return $d && $d->format($format) == $date;
    }
308046
public static function parseDate($date, $format){
        if( $format == "d/m/Y" ) return self::parseDate1($date, $format);
        if( $format == "Y-m-d" ) return self::parseDate2($date, $format);
        return null;
    }
642738
public static String getFormatDate(String format, Date date) {
        return getFormatDate(format, date, ZoneId.systemDefault().getId());
    }
717374
public function date($date, $format = null)
    {
        if ($this->isEmptyDate($date)) {
            return '';
        }

        $isLocalizerFormat = in_array($format, [Localizer::SHORT, Localizer::LONG, Localizer::VERBOSE]);

        if ($format && !$isLocalizerFormat) {
            return $this->toDateTime($date)->format($format);
        }

        if (!$this->localizer) {
            return $this->toDateTime($date)->format('Y-m-d');
        }

        return $this->localizer->date($date, $format ?: Localizer::SHORT);
    }
511482
protected function inputDate( $date, $format = null )
    {
        if ( ! $date instanceof DateTime )
        {
            if ( $date instanceof BaseDateTime )
            {
                $date = DateTime::createFromFormat(
                    DateTime::ISO8601,
                    $date->format( DateTime::ISO8601 )
                );
            }

            if ( is_int( $date ) )
            {
                $date = new DateTime( '@' . $date );
            }
            else if ( empty( $format ) )
            {
                $date = new DateTime( $date );
            }
            else
            {
                $date = DateTime::createFromFormat( $format, $date );
            }
        }

        return $date;
    }
905167
public function getDateTimeFormat(string $format='Y-m-d H:i:s')
    {
        $this->setDateTimeZone()->setDateTime();

        return $this->dateTime->format($format);
    }
681352
public static function DateFormat($format, $date = null)
  {
    if (!empty($date) && !is_int($date)) {
      $date = strtotime($date);
    }

    return strftime($format, $date ?: time());
  }
882011
static function shortDateString($date, $separator = '/') {
        str_replace('now', date('m.d.y'), $date);

        if (!self::parsable($date)) return null;

        $r = self::fromString($date);

        return $r->format('m' . $separator . 'd' . $separator . 'Y');
    }
677607
public static function date($format = "Y-m-d H:i:s", $time = null)
    {
        $time = ($time !== null ? $time : time());

        if (!is_numeric($time)) {
            $time = static::toUnix($time);
        }

        return date($format, $time);
    }
1353977
public function getDate($date, string $pattern = "Y-m-d")
    {
        if (!$date) {
            $this->data['ano'] = date("Y");
            $this->data['mes'] = date("m");
            $this->data['dia'] = date("d");
        } else {
            $this->prepareDate($date);
        }

        if($this->erro) {
            return null;
        } else {
            $originalDate = $this->data['ano'] . '-' . $this->data['mes'] . '-' . $this->data['dia'];
            return date($pattern, strtotime($originalDate));
        }
    }
1341257
public function parseDate($date)
    {
        $date = str_replace(['-', ':', '/', '.'], ' ', $date);
        $date_yyyy = $date_mm = $date_dd = $date_hh = $date_ii = $date_ss = 0;

        switch (sscanf($date, '%d %d %d %d %d %d', $date_yyyy, $date_mm, $date_dd, $date_hh, $date_ii, $date_ss)) {
            case 1:
                $date = sprintf('%04d/00/00 00:00:00', $date_yyyy);
                break;
            case 2:
                $date = sprintf('%04d/%02d/00 00:00:00', $date_yyyy, $date_mm);
                break;
            case 3:
                $date = sprintf('%04d/%02d/%02d 00:00:00', $date_yyyy, $date_mm, $date_dd);
                break;
            case 4:
                $date = sprintf('%04d/%02d/%02d %02d:00:00', $date_yyyy, $date_mm, $date_dd, $date_hh);
                break;
            case 5:
                $date = sprintf('%04d/%02d/%02d %02d:%02d:00', $date_yyyy, $date_mm, $date_dd, $date_hh, $date_ii);
                break;
            case 6:
                $date = sprintf('%04d/%02d/%02d %02d:%02d:%02d', $date_yyyy, $date_mm, $date_dd, $date_hh, $date_ii, $date_ss);
                break;
            default:
                $date = '0000/00/00 00:00:00';
        }

        return $date;
    }
367531
public static function isValidDate($date, $format = 'Y-m-d H:i:s')
    {
        $d = DateTime::createFromFormat($format, $date);

        return $d && $d->format($format) === $date;
    }
1079042
public static function valid_date($date = null, $format = 'DD/MM/YYYY')
    {
        if ($date == null) {
            return false;
        }
        $lendate = strlen($date);
        if ($lendate > 10) {
            $date = substr($date, 0, 10);
            $lendate = strlen($date);
        }
        
        if ($lendate >= 8 && $lendate <= 10) {
            $regexp = $format;
            $regexp = str_replace('DD', '(?<D>\d{2})', $regexp);
            $regexp = str_replace('MM', '(?<M>\d{2})', $regexp);
            $regexp = str_replace('YYYY', '(?<Y>\d{4})', $regexp);
            
            if (preg_match("/$regexp/", $date, $aDate)) {
                $year = ($aDate['Y'] < 100) ? 2000 + $aDate['Y'] : $aDate['Y'];
                $month = $aDate['M'];
                $day = $aDate['D'];
                
                if (self::checkdate($month, $day, $year)) {
                    return mktime(0, 0, 0, $month, $day, $year);
                }
                else {
                    return false;
                }
            }
            else {
                return false;
            }
        }
        else {
            return false;
        }
    }
1105914
static public function datetime($value=null, $format=null)
    {
        $value = static::toUnixtime($value);
        if (!$format) {
            $value = strftime('%Y-%m-%d %H:%M:%S', $value);
        } else {
            if (strpos($format, '%') === false) {
                $format = preg_replace('/([a-z])/i', '%\\1', $format);
            }
            $value = strftime($format, $value);
        }
        return $value;
    }