How can I get 2 digits in a time that I get from mySQL with PHP?
I am using this code for get only the time from a timestamp in mySQL with PHP.
$timestamp = strtotime($row['timestampSQL']); $time = date('G:i:s', $timestamp);
and this shows 3:00, would be so difficult to show 03:00?
Thanks again, Leandro.
AS you can see in the docs:
G 24-hour format of an hour without leading zeros 0 through 23
H 24-hour format of an hour with leading zeros 00 through 23
$time = date('G:i:s', $timestamp);
$time = date('H:i:s', $timestamp);
You are using
G: i: s
but should use
H: i: sto convert its time to 0X if the result of H is less than 10
here is an example
$query = $this->db->query("SELECT '2018-10-11 03:48:22' AS now"); $date = $query->row['now']; $time = date('H:i:s', strtotime($date)); print_r($time);
the result is: