views:

53

answers:

2

I have a table that has three different date columns, so I set each column as type 'date'.

However whenever im importing dates it seems to change them, and I have found it is because mysql does not allow null days and months.

My dates range from

1909-00-00 1963-09-00 1907-11-30

so sometimes we dont know the month, sometimes the day, and sometimes only the year was recorded.

Surely the 'proper' way to do this is to use some kind of date field but I have tried a variety of different layouts when importing the data and non works :( dd-mm-yyyy mm-dd-yyyy yyyy/dd/mm

Any suggestions?

A: 

I would suggest using a varchar then converting it when ever you need it to be a date. Here is a site with some date functions that would be useful.

northpole
Thanks birdlips, that is kinda where I came too. I was wondering though, why is there no function or field type for dates with null entries, this is often the case in historical apps!
Paul M
as far as I understand things the database will try to validate the date as it is entered. If it is invalid it will not allow you to store it. This is there to maintain data integrity. I don't think you have any options to store a non date value in a date field.
northpole
+1  A: 

There is no data structure that would act as a date but would allow 00 for any of the components. If you really insisted on emulating this, you could split the data into 3 columns - year, month, day and then write a complicated trigger to validate each update/insert query.

I wouldn't dare though. However, you asked, and I tried to answer. ;]

Artem Russakovskii