how to get time from MySQL database in PHP || PHP Examples
×


how to get time from MySQL database in PHP

2965

We Generally face the situation while creating any table in MySQL. When we are creating a column with type =TIME, we will get time in the following format

'YYYY-MM-DD HH:MM: SS'
i.e. 2019-03-21 20:26:12

If we want to get only time from the above-mentioned format, there are many methods that can be implemented. Two of them are illustrated with an example:

We have used strtotime() for converting the time string into a timestamp and a date() function for getting time format as per our requirement.

strtotime() function

$str = '2019-03-21 20:26:12';
echo date('g:i A', strtotime($str));

Output: 8:26 PM


date() function

$str = '2019-03-21 20:26:12';
echo date('g:i A ', $ts);

Output: 12:00 AM



Best WordPress Hosting


Share:


Discount Coupons

Get a .COM for just $6.98

Secure Domain for a Mini Price



Leave a Reply


Comments
    Waiting for your comments