How can we Convert this date format 2021-04-26 05:31:38 to 26 Apr, 2021 in Magento 2. Please let me know how can I do this.


After struggling for some time and checking in few date-time format related sites I got the answer myself that worked for me.

 $date = $_order->getCreatedAt();//2021-04-26 05:31:38   (input)
$date_month_name=date("M", mktime(0,0,0,$date_month,$date_day,$date_year));
echo $date_day." ".$date_month_name.", ".$date_year;//26 Apr, 2021  (output)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.