There is a field date format with birth dates. How to filter data with select for example> 55 years and <23 years

Decided in this way

$god передается через get if ($god == "23") {$znak = '<=23';} else {$znak = '>55'; } Запрос такой "YEAR(NOW())- YEAR(denrogdeniya)$znak"; 

And now how to choose all those from 23 to 55

    2 answers 2

     SELECT FROM_UNIXTIME(timestamp_column, '%Y') AS year FROM table_name WHERE FROM_UNIXTIME(timestamp_column, '%Y') BETWEEN (YEAR(CURDATE())-55) AND (YEAR(CURDATE())-23); 

      Well, you know what year should be if a person is 23 years old for example and here’s a query

      php

       `$today = date("m/d/y"); 

      sql

       Select * FROM table WHERE DateDiff(date,$today)<23 //23 года Select * FROM table WHERE DateDiff(date,$today)>55 //55 лет 
      • And if the year 2017 comes around? - Venta
      • Until 2017 still need to live. In general, subtract 23 from 2017 and get 1994. The condition in 2017 will be <1/1/1994. You can do differently if the database has arithmetic with dates. current_ between date of birth + 23 years and date of birth + 55 years. But the first option is simpler, since it does not require any additional calculations for each record - Sergey
      • then compatible with php condition to determine dynamically at php and transfer to Sql added to the response. - Broouzer King
      • I decided this way $ god is passed through get if ($ god == "23") {$ znak = '<= 23';} else {$ znak = '> 55'; } Request such "YEAR (NOW ()) - YEAR (denrogdeniya) $ znak"; And now how to choose all those from 23 to 55 - Sergey