user user - 1 year ago 67
SQL Question

mysql DATE datatype not takeing the correct value

i have created a table is the code

create table ddate(
ddate date);

after that i was trying to insert value like this

insert into ddate(ddate)value(2010-04-12);

But it is giving me a warning

insert into ddate(ddate)value(2010-04-12) 1 row(s) affected, 1
warning(s): 1264 Out of range value for column 'ddate' at row 1 0.001

Answer Source

Date literals are enclosed in single quotes, like a string literal.

insert into ddate(ddate)value('2010-04-12')
                              ^          ^

Without the single quotes around the literal, MySQL is evaluating that as a numeric value, the result of a calculation:

2010 - 04 - 12 

Which makes the original statement essentially equivalent to

insert into ddate(ddate)value( 1994 )
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download