简体   繁体   中英

Change date format in php from string format to another in PHP

I need to change date format in php from 1/11/2020 (String format) to 2020-11-01

Thanks in advance

Regards, Sathish

<?    
$date = "1/11/2020";   
$date = str_replace('/', '-', $date );
$sorted = date("Y-n-d", strtotime($date));

If you only need it to be presented that way and not actually changing the date stored, you can try using printf() as well

一个班轮:

echo (DateTime::createFromFormat('j/n/Y','1/11/2020'))->format('Y/m/d');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM