Agtronic Posted March 24, 2008 Share Posted March 24, 2008 Hey guys and gals, I have a database that contains user profiles. Users' date of birth are stored as unix timestamps, many of which are in the negative. I am able to calculate the age of the users once the timestamp has been pulled from the DB. What I'd like to do is pull users between the ages of (say) 40 and 50 years old. Question : How can I generate a timestamp value based on age so that I can use it in the MySQL query string? Any help would be greatly appreciated! Thank you for your time! Quote Link to comment https://forums.phpfreaks.com/topic/97669-how-to-generate-a-timestamp-based-on-age/ Share on other sites More sharing options...
rhodesa Posted March 24, 2008 Share Posted March 24, 2008 These should work: $start = strtotime("-40 years"); $end = strtotime("-50 years"); Quote Link to comment https://forums.phpfreaks.com/topic/97669-how-to-generate-a-timestamp-based-on-age/#findComment-499754 Share on other sites More sharing options...
monkeytooth Posted March 24, 2008 Share Posted March 24, 2008 stole my answer while I was typing Quote Link to comment https://forums.phpfreaks.com/topic/97669-how-to-generate-a-timestamp-based-on-age/#findComment-499762 Share on other sites More sharing options...
rhodesa Posted March 24, 2008 Share Posted March 24, 2008 That happens to me several times a day... Quote Link to comment https://forums.phpfreaks.com/topic/97669-how-to-generate-a-timestamp-based-on-age/#findComment-499769 Share on other sites More sharing options...
Barand Posted March 24, 2008 Share Posted March 24, 2008 or, SQL only, SELECT ..... WHERE FROM_UNIXTIME(dob) BETWEEN CURDATE() - INTERVAL 50 YEAR AND CURDATE() - INTERVAL 40 YEAR Quote Link to comment https://forums.phpfreaks.com/topic/97669-how-to-generate-a-timestamp-based-on-age/#findComment-499818 Share on other sites More sharing options...
Agtronic Posted March 24, 2008 Author Share Posted March 24, 2008 Holy isht! You guys are the greatest! Thanks so much!! Quote Link to comment https://forums.phpfreaks.com/topic/97669-how-to-generate-a-timestamp-based-on-age/#findComment-499857 Share on other sites More sharing options...
Barand Posted March 24, 2008 Share Posted March 24, 2008 These should work: $start = strtotime("-40 years"); $end = strtotime("-50 years"); Just being picky but the start date would be the -50 one, as it is earlier Quote Link to comment https://forums.phpfreaks.com/topic/97669-how-to-generate-a-timestamp-based-on-age/#findComment-499862 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.