Way to have MySQL Date field remain empty, no 0000-00-00

I am attempting to have a date field remain empty when the form is processed and the data is inserted into the MySQL database.  I would like the date field to remain empty, instead of populating with 0000-00-00.

Is there a way to do this without changing the datatype of the field?
tru504187211Asked:
Who is Participating?
 
Roger BaklundConnect With a Mentor Commented:
No, I don't think so. The 0000-00-00 is the internal "empty" for a NOT NULL date column. But you don't have to output this, you can change it in the select:
SELECT ... if(dateCol='0000-00-00','',dateCol) as dateCol, ... 
FROM ...

Open in new window

0
 
tru504187211Author Commented:
cxr:  Thanks for the reply.  I understand what you mean, partially about the if (datecol='0000-00-00'), but am unsure what could be done about it.  How could I go about doing...

If(datecol='0000-00-00')
display 'Today's Date instead'

...or somehow display today's date...
0
 
Roger BaklundCommented:
That would be like this:
SELECT ... if(dateCol='0000-00-00',CURDATE(),dateCol) as dateCol, ... 
FROM ...

Open in new window

0
 
Roger BaklundCommented:
The IF() function takes three parameters:  IF(<expression>,<true-output>,<false-output>)
0
 
tru504187211Author Commented:
Got it to work!  Thanks for the assistance!!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.