0

In my php code I insert datetime to my table like this:

php code:

$doinmysql = "INSERT INTO my_table (id,order_date) VALUES('0','date("Y-m-d H:i:s")')";
mysql_query($doinmysql);

if I echo date("Y-m-d H:i:s") I get "2015-08-27 15:48:19" - a time in 24 hour format, but in the db u have: "2015-08-27 03:48:19"- a time in 12 hour format.

any idea how I can solve this?

thanks!!!

edit:
if i run the same query in sql tab in phpmyadmin the date is insert in 24 hour format, still from my php to db he change.

Isaac Bennetch
  • 11,830
  • 2
  • 32
  • 43
Moshe Kamer
  • 27
  • 1
  • 7
  • Hi i think this link may help you.. http://stackoverflow.com/questions/986058/mysql-12-hr-to-24-hr-time-conversion – phpfresher Aug 27 '15 at 13:20
  • still after i used DATE_FORMAT same problem! – Moshe Kamer Aug 27 '15 at 13:28
  • Could you make a http://sqlfiddle.com with your schema and full query (with values) to make this easier for myself and others to diagnose? thanks. – Jamesking56 Aug 27 '15 at 13:46
  • If I try `$doinmysql = "INSERT INTO my_table (id,order_date) VALUES('0','date("Y-m-d H:i:s")')";` I get `PHP Parse error: syntax error, unexpected 'Y' (T_STRING)`. Can you post the exact code that you're running? I suspect you may be trying to use the MySQL `DATE()` function using a PHP date format. – Dezza Aug 27 '15 at 13:51

2 Answers2

0

Try to change your data/time format in db using:

SET GLOBAL datetime_format ='%Y-%m-%d %H:%i:%s';
SET GLOBAL time_format ='%H:%i:%s';

before you can also check which format you use:

show variables like 'date%format';
Tomasz
  • 4,847
  • 2
  • 32
  • 41
0

use mysql DATE_FORMAT function

SELECT DATE_FORMAT(order_date,'%Y-%m-%d %r'), order_date FROM my_table 

for more about DATE_FORMAT function - read more

abdullacm
  • 616
  • 5
  • 16