Check whether person is of legal age, if yes delete it

Asked

Viewed 179 times

-3

I need to make a query in MYSQL database to verify if a user is of age based on their date of birth compared to the current date.

If yes the user should be deleted from the database.

  • Where is your doubt? What have you tried so far?

  • The doubt is that I do not know how to compare the current date with the date of birth to check if you are 18 or not rsrs

  • I have no idea where to start

  • 3

    So I suggest we start by looking at search history here of the same site, which has several questions dealing with the difference between dates in SQL and with this you will be able to at least define a starting point.

1 answer

2


First, an example of how to get a date type value in mysql.

SELECT STR_TO_DATE('2019-04-15', '%Y-%m-%d');

Example of getting the difference between the dates

SELECT TIMESTAMPDIFF(YEAR,'2002-05-01','2001-01-01');

As for DELETE, you can do so:

DELETE FROM suaTabela WHERE TIMESTAMPDIFF(YEAR,'2002-05-01',CURDATE()) >=18;

It is a good north. Good studies!

  • kkk I would have done the process in the back-end language

Browser other questions tagged

You are not signed in. Login or sign up in order to post.