I have some date columns in my table.If there is no value for date i want them to be empty. They should not contain null or '0000-00-00'. I have seen many solutions but all are passing null or 0 date. I dont want to pass anything if there is no date value. For this what should be the schema for my date column and how can i pass empty value to it.
Asked
Active
Viewed 1,001 times
1
-
may be not `NOT NULL DEFAULT '0000-00-00` – Abhik Chakraborty Mar 11 '15 at 08:42
-
I dont even want to pass '0000-00-00'. i want them blank. – Ruchi Mar 11 '15 at 08:43
-
**[What have you tried so far?](http://stackoverflow.com/questions/1691117/how-to-store-null-values-in-datetime-fields-in-mysql)** – Amit Verma Mar 11 '15 at 08:47
-
If i pass blank to them like '' it adds 00 date, if i pass null it adds null. If i dont use these columns it keeps them null. Blank in no case. – Ruchi Mar 11 '15 at 08:53
-
2You are totally do not understand how databases work. You cannot save empty string into date column (only dates or NULL). You can use varchar column, format your dates in app and save it as string. But you will lose all advantages and capabilities of date type. This is the reason why you cannot find solution for this problem. – kba Mar 11 '15 at 09:02
-
Are you viewing your table with phpMyAdmin and see `NULL` written there? It's just phpMyAdmin's way to tell you there's no value, it IS empty. – Marek Mar 11 '15 at 09:19
-
I understand that it is the database way to tell that they are NULL. But for some other fields say VARCHAR we can keep blank. What if a person wants to keep these fields blank not NULL. My question can be weird. But it is quite strange for me that we cannot keep date columns totally blank in DB. – Ruchi Mar 11 '15 at 09:24
-
If the person wants to keep date field blank then you have to use NULL on database level if you want to also use some kind of date type. That's it. Empty value in varchar is just illusion. In fact, it is empty string or string with zero length. Not some kind of blank value. – kba Mar 11 '15 at 10:42
1 Answers
1
Could you provide some context as to why you don't wish to write NULL
to the field?
The very definition of NULL
is that it represents the absence of a value in that field. The way you refer to 'empty' makes it sound like this is what you are after; having no value for that field. NULL
accomplishes this.

NathanR
- 196
- 10