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

Bonsai Boy of New York Bonsai Trees and Accessories

Website Domains Names & Hosting | Domain.com

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

Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

DreamHost Web Hosting


Liquid Web Cloud VPS 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.

13,237 questions

18,022 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 by avibootz
edited May 19 by avibootz
...