How do I select birthdays in the next 30 Days

user12023410

I have a table with birthdates and I want to select all the birthdays that will come in the next 30 days.

The situation is, that all the birthdays are written in the form off 1999-09-15 which means that even if I tried selecting the next 30 days, the birthdays wouldn't show up because the year is 1999.

I am running Microsoft Server 2016.

SELECT * from dbo.EMPLOYEES
WHERE DATE <= DATEADD(day, +30,GETDATE()) 
and   DATE >= getdate()
order by "DATE"
Zeina

To get the birthdate, we need to work only on the days and the months, not on the year. Thats why we cannot get Where date between 2 dates.

SELECT 
  dateofbirth_c AS BIRTHDAY
 ,FLOOR(DATEDIFF(dd,EMP.dateofbirth_c,GETDATE()) / 365.25) AS AGE_NOW
 ,FLOOR(DATEDIFF(dd,EMP.dateofbirth_c,GETDATE()+30) / 365.25) AS AGE_30_Days_FROM_NOW
FROM 
  Employees EMP
WHERE 1 = (FLOOR(DATEDIFF(dd,EMP.dateofbirth_c,GETDATE()+30) / 365.25))
          -
          (FLOOR(DATEDIFF(dd,EMP.dateofbirth_c,GETDATE()) / 365.25))

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How do I force a start date to be at least 30 days before an end date when registering?

How do I configure elasticsearch to retain documents up to 30 days?

How do I select the next `td` in this `tr`?

Starting from the beginning of a sequence, I need to delete any instance that is less than 30 days from the next instance

How do I generate a random timestamp in the next 5 days in Python?

How do I account for leap years and months with 30 days in custom date picker drop downs?

I Want to Show only The Dates from a MySQL Database Between Today and the Next 30 Days

SQL -- How do I write a select statement that finds customers who placed orders on 5 consecutive days

Finding next 30 days from today

How to select last 30 days dates in MySQL?

I Need to count records in next 30 days from start_date?

Count of birthdays for next 7 days and need count for each day and total

Bootstrap 3 DateTimePicker (eonasdan) - How to quickly select year? (for birthdays)

how to display next 30 days records , based on the input data?

How do I find and select a next bold word

how to select last 30 days mysql record and group by each day

How to return a dataset for next 30 days group by each day

How do I define a function detailing 30 days ago in ssrs?

how to calculate next 30 days from current date (MySQL)?

Filtering queryset by next 30 days and date passed

Putting Next 30 days into array

Scrapy: How do I select the next `td` in this `tr`?

How do I unhighlight text if a document hasn’t been updated in 30 days

PHP How do I find the number of days until the next January 1 (without specifying the year)?

MySQL: How do I create a query that returns rows from last 30 days and 15 days?

Finding birthdays in next 30 Days using day, month and no year

how to select all date exclude 30 days before today

How do I query the last 30 days on CosmosDB?

Get employees birthdays within next 3 days including today in Laravel