I store dates in mysql databse in a date field like this......
09/03/2018|29/03/2018|17/06/2018|10/07/2018|28/10/2019|12/02/2019
In php I convert the above date formats into an array...
$currentyear= date("Y");
$this_month = array();
$other_month = array();
$dates_list = @explode("|", $dates_list);
$dates_list = str_replace(array("", "
"), '', $dates_list);
foreach($dates_list as $date)
{
if(strstr($date,$month))
{
array_push($this_month,$date);
} else {
array_push($other_month,$date);
}
}
It's the $other_month array I wish to filter
So in the following array 09/03/2018|29/03/2018|17/06/2018|10/07/2018|28/10/2019|12/02/2019
it would only show the last two dates.
I would like to filter out all none "current year" dates, if anyone can help it would be greatly appreciated.
Thank you
I don't really prefer what you are doing DB wise, however to filter your array here is a script:
$this_year = [];
$other_years = [];
foreach ($dates_list as $date) {
if (date('Y', strtotime($date)) == date('Y')) {
$this_year[] = $date;
} else {
$other_years[] = $date;
}
}