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";

Author: Mukesh Jakhar

This is Mukesh Jakhar. I’m a professional web developer with 3+ years experience. I am always ready for freelance work and i am writing blogs in my free time. I love to learn new technologies and share with others.
I founded PHPKIDA in September 2015. The focus of this website to provide web development tutorials of PHP, WordPress, CodeIgniter, Jquery, MySQL, HMTL, CSS etc and sharing solution of problems which i already solved.

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Posts: You may like

All Full Forms Related to Database

How to login with LinkedIn oAuth2 in PHP

Extract Total Number of Image And Missing Alt Attribute using php

How to extract Heading tags using PHP from string

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

Redirecting HTTP to HTTPS with PHP

Convert Base64 string to an image file

PHPKIDA Offering Free Tools:

INSTA DOWNLOADER

Free online tool to download Instagram videos, photos and save Instagram videos, photos to your device. It's free & easy to use.

Download Now

CURRENCY CONVERTER

Our real time currency converter calculator will convert your money based on current values from around the world. It's free & easy to use.

Convert Now

ROBOST.TXT GEN.

Create robots txt file that help search engines to crawling and indexing your site with help of our free online Robots.txt Generator tool.

Create Now

HTML MINIFIER

Free online tool to minify or compress html code and reduce the size of html code in few clicks. It's free & easy to use.

Minify Now

CSS MINIFIER

Free online tool to minify or compress css code and reduce the size of css code in few clicks. It's free & easy to use.

Minify Now

JAVASCRIPT MINIFIER

Free online tool to minify or compress javascript code and reduce the size of javascript code in few clicks. It's free & easy to use.

Minify Now

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.