user85
user85

Reputation: 1596

Error while inserting value in datetime column

I'm trying to insert a record (from java code) in table but I'm getting "ERROR 1292 (22007)". The timestamp column is of type "datetime" Following is my query

insert into Alert(name,timestamp,location,message) values ("aaa", "2013-04-25 5:47:3PM","XYZ", "bla bla bla");

Error

ERROR 1292 (22007): Incorrect datetime value: "2013-04-25 5:47:3PM" for column 'Timestamp' at row 1

Upvotes: 0

Views: 6313

Answers (3)

thibaultcha
thibaultcha

Reputation: 1320

Your datetime formatting is wrong. Try:

2013-04-25 05:47:03

It's because datetime is based on a 24H format.

Here is the documentation about date formats in MySQL: http://dev.mysql.com/doc/refman/5.1/en/datetime.html

Upvotes: 0

Ed Gibbs
Ed Gibbs

Reputation: 26343

You need to use a 24-hour clock and get rid of the AM/PM. This will insert the same time you're attempting to insert in your question:

insert into Alert(name,timestamp,location,message)
  values ("aaa", '2013-04-25 17:47:3',"XYZ", "bla bla bla");

Upvotes: 0

Change the timestamp value in your query to 2013-04-24 17:47:03. The format for a datetime column must be yyyy-MM-dd HH:mm:ss.

Upvotes: 1

Related Questions