I am trying to join two tables using mysql, this is not difficult, my problem is the column I am joining on has a nonstandard type, I am joining on the birthday column which can come in a variety of different styles:
10/29
01/10/1984
12/32/2007
10/1997
null
1984
I only want to join the columns if the users are from the same year, so in the above example
01/10/1984
1984
Would be allowed for a join, while the others would be ignored.
Does mysql offer a way to split the birthdays into just their year components?
You could may be join using the RIGHT()function, to join on only the last 4 digits of the date, and also use INSTR() to check that the last 4 digits do not contain ‘/’ (ie making sure it is a year).
Something like this:
This relies on the fact that the year is always the last four digits of the field.