How to get AM/PM from a datetime in PHP

You need to convert it to a UNIX using strtotime and then back into the format you require using the date function.

Use strtotime() to make the date a UNIX timestamp.

Code

<?php
    $date = '2018-01-31 10:43:23';
    date('d-m-Y h:i A', strtotime($date));
?>

Another Code

<?=date('d-m-Y h:i A', strtotime($value->created_date));?>

Leave a Reply

Your email address will not be published. Required fields are marked *