0

I have a csv file with customer birth dates that looks like:

CUST_BIRTH_DT
1955-07-10

When I import the data into my table, I want MySQL to calculate the age and replace the actual birth date with the age.

Is that possible in MySQL? If so how do I do it?

I've looked on stack overflow already and tried possible things and I have had no luck.

PM 77-1
  • 12,933
  • 21
  • 68
  • 111

1 Answers1

0

I started writing a solution which uses a function in LOAD DATA to convert the birthdate to an age, but then I stopped, because I don't think this is a good idea. Customer age is something which is always changing, getting larger in fact, as time progresses. This means that whatever age you set when reading in your data will become stale at some point, depending on the resolution of the age (e.g. years only, year/months/days, etc.).

So I would actually recommend generating the age when you query your table:

SELECT CUST_ID,
       DATEDIFF(NOW(), CUST_BIRTH_DT) AS age
FROM yourTable
Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360