Q:

How to get current datetime in codeigniter in 24 hour format

I'm trying to get the current datetime in codeigniter for my school project.
I made a sample function in controller for this which looks like this:
public function sample(){
        date_default_timezone_set('Asia/Manila');
        echo date('y-m-d h:i:s');
    }

however, i found out that this outputs 20-01-20 04:52:19 instead of 20-01-20 16:52:19.
any idea how to fix this ? thanks .

A:

For 24 hour format of hours, use y-m-d H:i:s (uppercase H instead of lowercase h): 
echo date('y-m-d H:i:s');   // Outputs: 20-01-20 17:04:00

As per the docs:

H 24-hour format of an hour with leading zeros    00 through 23

For PM times you would get the 24 hour format, and for AM times, you would get the leading zero (eg: 05:04:13).
If you prefer 24 format without leading zeros (16 for PM, 4 for AM), you can use G:
echo date('y-m-d G:i:s');   // Outputs for AM: 20-01-20 5:04:00 

// 12 hours later...
echo date('y-m-d G:i:s');   // Outputs for PM: 20-01-20 17:04:00

G     24-hour format of an hour without leading zeros 0 through 23

