简体   繁体   中英

convert date in php day/month name, year

I have a query that inserts date in this format

$time = date("m-d-y");

But when I Fetch and output date it shows wrong date. real: October 2020 but outputs: January 1970

$time = $row1['time'];
$newDate = date('F Y', strtotime($time));
echo $newDate;

How do I output date in this format: 20 OCT, 2020

Try not to store date/time using varchar datatype. If you can change it, please do. However, if you can't change database structure, you can use date_create_from_format() to create a DateTime object from a custom format:

echo date_create_from_format('m-d-y', "10-29-20")->format('F Y');

Output:

October 2020

Edit : Change the format part to ->format('d M, Y') to match your desired format Output:

29 Oct, 2020

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