Currently, my code to insert into the database is as follows:
mysql_query("INSERT INTO lookup_table (
the_date
)
VALUES(
NOW()
)
";)
In one line, that’s:
mysql_query("INSERT INTO lookup_table (the_date) VALUES(NOW())";)
The problem is, for some reason, NOW() as I have it here is recording into the database a 12-hour clock. (1:03 PM records as 01:03:00, instead of 13:03:00.)
What can I do to specify to NOW() that it be formatted as 24-hour?
I have read a lot about formatting things. Unfortunately, as has happened many times in the past, there are small, almost imperceptible formatting issues that can make things not work out quite right.
I am trying to make sure I do not do a long time of trial-and-error to make sure I get the formatting correct.
I THINK that the line that says “NOW()” should be replaced with “DATE_FORMAT(NOW(), %Y-%m-%d %T)“, but I am looking for independent confirmation that does not have me leading the witness, and someone saying “yeah that looks good enough.”
Right now, entries in the database look like this:
2012-06-27 01:03:36
Which would be perfect, were it not that the time should read 13 instead of 01, like so:
2012-06-27 13:03:36
I know that “NOW()” is working, it just needs to be 24 hour format, which it is SUPPOSED to be by default. For some reason this is not happening, and I’d just like to know what specific alphanumeric sequence to put in the stead of “NOW()” to record as a 24-hour format.
Given the documentation for
NOW(), I suspect that either your system is configured very strangely somehow, or you’re in a time zone which is currently 12 hours “out” from UTC. (Or your server is configured to just use UTC, so it’s giving the UTC time but you were expecting local time.) There’s no indication from the documentation that the format returned byNOW()is affected by any cultural settings, for example.I would suggest that in general, storing the result of
UTC_TIMESTAMP()would be a better approach anyway – but of course you’ll still want to make sure you end up with a sensible format.What do you see in the morning, and do you see the same effect if you just use
from an interactive query window? Likewise, do you have any other servers you could try the same query against? Which version of MySQL are you running?