0

I need the biggest date from current year.

I have an date array as :

$dateArray = array('2019-05-12','2019-04-02','2020-01-07','2019-11-10','2020-07-13','2019-08-15');

As current year is 2019 so I need the value 2019-11-10 as my result.

Alive to die - Anant
  • 70,531
  • 10
  • 51
  • 98
MagentoDev
  • 15
  • 2

2 Answers2

0

First filter the current year by using array_filter then use max

 $dateArray = array_filter($dateArray, function($v){return strpos($v, date('Y')) !== false ? $v : '';});
 echo max($dateArray);

Working example : https://3v4l.org/eONDq

Rakesh Jakhar
  • 6,380
  • 2
  • 11
  • 20
0
$max = max(array_map('strtotime', $arr));
echo date('Y-m-j H:i:s', $max);
Anna Ned
  • 1
  • 1