PHP time does not show PM, only AM

I am using the current time and date in MySQL using

$datecreated = date("Y-m-d, g:i:s A");

Then showing it to the user

$datecreated = date('n-j-Y, g:i:s A', strtotime($row['datecreated']));

Everything works fine, except that time is always AM. I checked it in the morning and afternoon, and still AM.

+3
source share
6 answers

Use date("Y-m-d H:i:s")(24 hour recording) when writing to the database.
Otherwise, the “PM” (or “AM”) part simply truncates, leaving you always with the “AM” situation.

+3
source

You must use a field DATETIMEthat stores dates and times in a 24-hour format.

You can use the MySQL NOW function to store the current time:

INSERT INTO mytable
(mydatefield)
VALUES
(NOW())

PHP, :

$datecreated = date('Y-m-d H:i:s');

24- . PHP date MySQL DATE_FORMAT, 12- .

+2

, , 12- . g "G" ( ) "H" ( ), 24- (0-23), "g" - 12- (0-12).

0

( "Y-m-d, G: i: s" )?

0

, , .

0

MySQL, 24- . MySQL, , AM/PM , AM.

$datecreated = date("Y-m-d H:i:s");
0

All Articles