How to format DateTime object in PHP

4 Answers

0 votes
$date = new DateTimeImmutable('2023-09-27 11:32:17');

echo $date->format('Y-m-d H:i:s');
    
   
    
       
/*
run:
            
2023-09-27 11:32:17
     
*/

 



answered Sep 27, 2023 by avibootz
0 votes
$date = new DateTimeImmutable('2023-09-27 11:32:17');

echo date_format($date, 'Y-m-d H:i:s');
    
   
    
       
/*
run:
            
2023-09-27 11:32:17
     
*/

 



answered Sep 27, 2023 by avibootz
0 votes
$date = new DateTimeImmutable('2023-09-27 11:32:17');

echo $date->format('l jS \o\f F Y h:i:s A');
   
    
    
       
/*
run:
            
Wednesday 27th of September 2023 11:32:17 AM
     
*/

 



answered Sep 27, 2023 by avibootz
0 votes
$date = new DateTimeImmutable('2023-09-27 11:32:17');

echo $date->format('l \t\h\e jS');
   
    
    
       
/*
run:
            
Wednesday the 27th
     
*/

 



answered Sep 27, 2023 by avibootz
...