You are here

public function ContentHubFilter::changeDateFormatMonthDayYear2YearMonthDay in Acquia Content Hub 8

Change Date format from "m-d-Y" to "Y-m-d".

Overrides ContentHubFilterInterface::changeDateFormatMonthDayYear2YearMonthDay

File

acquia_contenthub_subscriber/src/Entity/ContentHubFilter.php, line 249

Class

ContentHubFilter
Defines the ContentHubFilter entity.

Namespace

Drupal\acquia_contenthub_subscriber\Entity

Code

public function changeDateFormatMonthDayYear2YearMonthDay() {
  if (!empty($this->from_date)) {
    if ($from_date = \DateTime::createFromFormat('m-d-Y', $this->from_date)) {
      $this->from_date = $from_date
        ->format('Y-m-d');
    }
  }
  if (!empty($this->to_date)) {
    if ($to_date = \DateTime::createFromFormat('m-d-Y', $this->to_date)) {
      $this->to_date = $to_date
        ->format('Y-m-d');
    }
  }
  return $this;
}