Short Upcoming Birthday MySQL Queries

In this tutorial we are writing MySQL query to sort upcoming birthdays based on current date, here writing three number of queries these may be help of to reach your result.

Query 1. Upcoming birthday MySQL Queries

$sql = "SELECT * ,CASE WHEN BirthdayThisYear>=NOW() THEN BirthdayThisYear ELSE BirthdayThisYear + INTERVAL 1 YEAR END AS NextBirthday FROM ( SELECT * ,`emp_birthday` - INTERVAL YEAR(`emp_birthday`) YEAR + INTERVAL YEAR(NOW()) YEAR AS BirthdayThisYear FROM `hs_hr_employee` ) AS bdv WHERE `emp_birthday` != 'NULL' ORDER BY NextBirthday";

Query 2. Upcoming birthday MySQL Queries

I tried to get the upcoming birthday from a employee table, for the next 90 days. Using :

$sql ="SELECT * FROM hs_hr_employee WHERE emp_status = '1' AND emp_birthday >= DATE_SUB(CURDATE(), INTERVAL YEAR(CURDATE()) - YEAR(emp_birthday) YEAR) AND emp_birthday <= DATE_ADD(DATE_SUB(CURDATE(), INTERVAL YEAR(CURDATE()) - YEAR(emp_birthday) YEAR), INTERVAL 365 DAY) ORDER BY emp_birthday";

Query 3. Upcoming birthday MySQL Queries

$sql = "SELECT *, emp_birthday + INTERVAL(YEAR(CURRENT_TIMESTAMP) - YEAR(emp_birthday)) + 0 YEAR AS currbirthday, emp_birthday + INTERVAL(YEAR(CURRENT_TIMESTAMP) - YEAR(emp_birthday)) + 1 YEAR AS nextbirthday FROM hs_hr_employee WHERE emp_birthday !='NULL' AND emp_status='1' ORDER BY CASE WHEN currbirthday >= CURRENT_TIMESTAMP THEN currbirthday ELSE nextbirthday END";

Leave a Reply

Related Posts: You may like

How to remove whitespace from string using php

Remove All Special Characters From String PHP

comma separated values in mysql query

SQL statement to retrieve names beginning with A

Tools:

Crypto Currency

PHPKIDA provides free online the best real-time crypto market price, news, predictions, index with graphs & historical data for 2000+ coins including bitcoin, ethereum, & altcoins from major cryptocurrency exchanges.

Visite Tool

Icon Generator

PHPKIDA provides free online icon generator. Our icon generator help you to edit, modify, resize and customize icon for your website and applications. Convert to a shap you like add icon border, you can change icon border color, border size, background color, icon shadow, icons color, icon size in your own way and save it as a png image.

Visite Tool

Youtube Video Downloader

PHPKIDA provides Free online YouTube video downloader to download YouTube videos quickly in MP4, 3GP, and more. Search your video and free fast download youtube videos.

Visite Tool

Sign up for weekly update

Milkshake is almost ready. If you're interested in testing it out, then sign up below to get exclusive access.