Skip to content
Advertisement

get date range from date of birth

I am creating a peers page for my website and I am trying to get a query that can fetch users from the users table which is structured as id, name, gender, dob. The query should fetch the users relative to the logged user’s date of birth, i.e users who’s dob is either 2 years less or 3 years more than the logged user’s dob. The dob in the table is structured like 1993-03-23. I need help with the query so that it meets my requirements. This is a basic sample query.

JavaScript

Advertisement

Answer

If You know logged user dob can use next approach:

JavaScript

Share PHP code online

In case you have only logged user id – use next query:

JavaScript

Run & test PHP code online

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement