Ublaboo\DataGrid\Utils\DateTimeHelper::tryConvertToDate PHP Method

tryConvertToDate() public static method

Try to convert string into DateTime object from more date formats
public static tryConvertToDate ( mixed $value, array $formats = [] ) : DateTime
$value mixed
$formats array
return DateTime
    public static function tryConvertToDate($value, array $formats = [])
    {
        return static::fromString($value, $formats);
    }

Same methods

DateTimeHelper::tryConvertToDate ( string $value ) : DateTime

Usage Example

Beispiel #1
0
 /**
  * @param  mixed  $row
  * @param  FilterDateRange $filter
  * @return void
  */
 public function applyFilterDateRange($row, FilterDateRange $filter)
 {
     $format = $filter->getPhpFormat();
     $condition = $filter->getCondition();
     $values = $condition[$filter->getColumn()];
     $row_value = $row[$filter->getColumn()];
     if ($values['from'] !== NULL && $values['from'] !== '') {
         $date_from = DateTimeHelper::tryConvertToDate($values['from'], [$format]);
         $date_from->setTime(0, 0, 0);
         if (!$row_value instanceof \DateTime) {
             /**
              * Try to convert string to DateTime object
              */
             try {
                 $row_value = DateTimeHelper::tryConvertToDate($row_value);
             } catch (DataGridDateTimeHelperException $e) {
                 /**
                  * Otherwise just return raw string
                  */
                 return FALSE;
             }
         }
         if ($row_value->getTimeStamp() < $date_from->getTimeStamp()) {
             return FALSE;
         }
     }
     if ($values['to'] !== NULL && $values['to'] !== '') {
         $date_to = DateTimeHelper::tryConvertToDate($values['to'], [$format]);
         $date_to->setTime(23, 59, 59);
         if (!$row_value instanceof \DateTime) {
             /**
              * Try to convert string to DateTime object
              */
             try {
                 $row_value = DateTimeHelper::tryConvertToDate($row_value);
             } catch (DataGridDateTimeHelperException $e) {
                 /**
                  * Otherwise just return raw string
                  */
                 return FALSE;
             }
         }
         if ($row_value->getTimeStamp() > $date_to->getTimeStamp()) {
             return FALSE;
         }
     }
     return TRUE;
 }
All Usage Examples Of Ublaboo\DataGrid\Utils\DateTimeHelper::tryConvertToDate