How to get current datetime in codeigniter in 24 hour format [duplicate] How to get current datetime in codeigniter in 24 hour format [duplicate] codeigniter codeigniter

How to get current datetime in codeigniter in 24 hour format [duplicate]


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


use H in stead of h

echo date('y-m-d H:i:s');


Use H instead of h like below:

echo date("y-m-d H:i:s");

For more help, you may read the original doc of php https://www.php.net/manual/en/function.date.php