Skip to content

Instantly share code, notes, and snippets.

@fcaldarelli
Created May 20, 2019 23:42
Show Gist options
  • Save fcaldarelli/bdc782be7b48aa91e25bb4ac22fa779f to your computer and use it in GitHub Desktop.
Save fcaldarelli/bdc782be7b48aa91e25bb4ac22fa779f to your computer and use it in GitHub Desktop.
<?php
class DateTraitQuery
{
public function andWhereDate($attribute, $value, $separators = ['/','-'])
{
$array = null;
foreach($separators as $separator)
{
if(strpos($value, $separator) !== false) $array = explode($separator, $value);
}
if($array == null) $array = [ $value ];
$this->andWhere(['like', $attribute, implode('-', array_reverse($array))]);
}
public function andFilterWhereDate($attribute, $value, $separators = ['/','-'])
{
if($value)
{
$this->andWhereDate($attribute, $value, $separators);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment