priyamp mp1
priyamp mp1

Reputation: 27

Mysql Date Default insert in 1970-01-01

I am inserting an empty date-field, but a default value 1970-01-01 gets inserted automatically. Why?

I even changed the Date structure to allow null, set Default as Null, still it's inserting 1970-01-01.

Upvotes: 0

Views: 4428

Answers (2)

Jester
Jester

Reputation: 1408

You are most likely inserting an empty string. Inserting an entry string will result in 1970-01-01 being written instead. You have to really insert NULL if you don't want this to happen.

What you want to do is:

INSERT INTO table
SET datefield = NULL

Not "NULL" but NULL Otherwise it will read it as a string and not as NULL

You can also just don't set the column at all in your insert and than it will use NULL as well

Upvotes: 0

Daniel Madurell
Daniel Madurell

Reputation: 78

It's the default behavior of MySQL, check in the Database that the field can be NULL.

Check this: old post

Upvotes: 1

Related Questions