Help
cancel
Showing results for 
Search instead for 
Did you mean: 
Copilot Lvl 2
Message 1 of 5

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.

4 Replies
Copilot Lvl 2
Message 2 of 5

Re: Mysqli date field query

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

 

e.g.  INSERT INTO TABLE VALUES (1, NULL, ...)

Copilot Lvl 2
Message 3 of 5

Re: Mysqli date field query

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?

Copilot Lvl 2
Message 4 of 5

Re: Mysqli date field query

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

Commander Lvl 2
Message 5 of 5

Re: Mysqli date field query

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

 

Please follow-up to let us know how you made out. For good karma, mark a reply as the answer if it helped!