I am assuming your table is setup like this:
name age date
| Jack | 23 | 2003-03-04 |
|Sarah | 23 | 2003-03-27 |
| Jen | 12 |2002-12-02 |
So you would like a function that would only return Jack and Sarah.
correct?
To do any sort of mathematical comparison to dates, it is suggested to use the mktime() function
From the manual:
mktime() is useful for doing date arithmetic and validation, as it will automatically calculate the correct value for out-of-range input. For example, each of the following lines produces the string "Jan-01-1998". Example 1. mktime() example
echo date ("M-d-Y", mktime (0,0,0,12,32,1997));
echo date ("M-d-Y", mktime (0,0,0,13,1,1997));
echo date ("M-d-Y", mktime (0,0,0,1,1,1998));
echo date ("M-d-Y", mktime (0,0,0,1,1,98));
You can also do it directly from your SQL statement:
http://www.mysql.com/doc/en/Date_and_time_functions.html
//The following query selects all records with a
// date_col value from within the last 30 days:
SELECT something FROM tbl_name
WHERE TO_DAYS(NOW()) - TO_DAYS(date_col) <= 30;