Welcome to collectivesolver - Programming & Software Q&A. A website you can trust. All programs tested and work.

aviboots(AT)netvision.net.il

Instant Grammar Checker - Correct all grammar errors and enhance your writing

BlueHost Web Hosting Black Friday
BlueHost Web Hosting Black Friday

Bonsai Boy of New York Bonsai Trees and Accessories

DreamCloud The Comfortable Luxury Mattress Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

DreamHost Web Hosting


Disclosure We are a professional Programming & Software Q&A website, that receives compensation from some of the links whose we show you with Information. It means that my content may contain affiliate links.

16,295 questions

21,766 answers

573 users

How to sort an array of dates in ascending order with PHP

1 Answer

0 votes
function compareByTimeStamp($time1, $time2) { 
    if (strtotime($time1) < strtotime($time2)) 
        return 1; 
    else if (strtotime($time1) > strtotime($time2))  
        return -1; 
    else
        return 0; 
} 
  
$arr = array("13-02-2007",
             "19-04-2011",               
             "18-04-2011",
             "01-03-1966",
             "17-05-2019",
             "17-12-1980",
             "21-06-2017",
             "17-05-2020"); 
 
usort($arr, "compareByTimeStamp"); 
  
print_r($arr); 



/*
run:

Array
(
    [0] => 17-05-2020
    [1] => 17-05-2019
    [2] => 21-06-2017
    [3] => 19-04-2011
    [4] => 18-04-2011
    [5] => 13-02-2007
    [6] => 17-12-1980
    [7] => 01-03-1966
)

*/

 




answered May 19, 2020 by avibootz
edited May 19, 2020 by avibootz
...