0

I'm just trying to select the persons that are not yet 30. Table:

+--------+-------+------------+
| fname  | lname |    dob     |
+--------+-------+------------+
| Steven | Carl  | 1964-07-07 |
| John   | Handy | 1980-06-03 |
| Mary   | Jane  | 2000-11-12 |
+--------+-------+------------+

I've tried doing something like that, I know that checks for today's date and it is wrong.

CAST(CURRENT_TIMESTAMP AS DATE)

Maybe I can subtract the year with 30 and check for that date or something like that?

SELECT  fname, lname,  FROM Persons
WHERE dob >= CAST(CURRENT_TIMESTAMP AS DATE);
bon123
  • 61
  • 1
  • 6
  • 1
    Does this answer your question? [How to get an age from a D.O.B field in MySQL?](https://stackoverflow.com/questions/2533890/how-to-get-an-age-from-a-d-o-b-field-in-mysql) – Eray Balkanli Dec 10 '19 at 21:30

1 Answers1

2

Use date arithmetic:

select * from persons where dob + interval 30 year > curdate()
GMB
  • 216,147
  • 25
  • 84
  • 135