javascript - Get upcoming birthday from a set of timestamps

I've got a database with names, sex and birthday saved as a timestamp. Database is read by API done in PHP and returns full set of records with all the details, including "born" column containing the timestamp.

I would like to get upcoming birthdays for X days, lets say in next 7 days.

What is the easiest way to do it? I can change the year to current one, but would have to check if the date is in the past from today, I would have to add +1 to the year, so for example if now it is November and birthday is in March, it would be March next year.

Anyone has an idea for cleaner solution? Either in JavaScript, or PHP (I can also make getBirthday/(x) API calls to get birthdays in X upcoming days.

Answer

Solution:

If you have a UNIX_TIMESTAMP in your database and want to query it you can if it is a regular date field.

select * from user where `user.birtday` < (NOW() + INTERVAL 7 DAY);

If you want to see the UNIX_TIMESTAMP in a human-readable format use this.

select DATE_FORMAT(FROM_UNIXTIME(`user.birtday`), '%Y-%m-%d %H:%i:%s') from user;

Source