Mysqli date field query

Hello everyone. I have a query. Whenever I give a null value under the date field, its storing the value as 01-01-1970 or 00-00-0000 by default. I want it to just get stored as a blank space or a null value. How can I achieve it? Thanks in advance.

When you insert a value into the table, where the datetime position is, put the value as NULL instead of the date


What if we take the value from a form or some frontend method and store it into the database? what is the solution for that?

I’m not too sure as I’m still pretty new to sql, but you could try running an update and have the condition as IS NOT NULL and update the field to IS NULL

e.g. UPDATE table SET datetime = NULL WHERE datetime IS NOT NULL;

I’m not sure if this will work, but you can give it a shot

Use a string column, not datetime. Set it to blank or empty if null.

1 Like