Tuesday, March 19, 2013

How to get most recent date from an array of dates?

  $all_dates = array(
    "15-03-2015-14:50",
    "16-03-2013-14:50",
    "15-08-2017-14:52",
    "15-03-2014-14:50",
    "20-03-2016-14:50",
  );
  //
  foreach($all_dates as $date_one){
    $date_one_to_string = strtotime($date_one);
    $all_date_strings[$date_one] = $date_one_to_string;
  }
  arsort($all_date_strings);
  $latest_date_strings = current($all_date_strings);
  $key = array_search($latest_date_strings, $all_dates);
  print 'Latest Date Is :'.$latest_date_strings;

No comments:

Post a Comment