Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 how to get birthdays of users of current week

Author  Topic 

swathigardas
Posting Yak Master

149 Posts

Posted - 2008-12-08 : 01:03:22
select e.first_NM,Birth_DT from Temployee e,TEmployee_info ei where e.employee_nbr=ei.employee_nbr and birth_dt between '11/30/2008' AND'12/06/08'

Hi. I use the above query to get birthdays of employees in that date range. But i need a query which will give the birthdays of the current week . Is there any way to do this .
Thanks in advance

ayamas
Aged Yak Warrior

552 Posts

Posted - 2008-12-08 : 01:15:47
The query below will get the startdate & enddate of the current week.
SELECT DATEADD(wk, DATEDIFF(wk,6, getdate()), 6) as startdateofweek,
DATEADD(dd,7,DATEADD(wk, DATEDIFF(wk, 6, getdate()), 6))as enddateofweek
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-12-08 : 03:28:35
[code]select e.first_NM,Birth_DT from Temployee e,TEmployee_info ei where e.employee_nbr=ei.employee_nbr and MONTH(birth_dt)= MONTH(GETDATE())
AND DAY(birth_dt)>=DAY(DATEADD(wk,DATEDIFF(wk,0,GETDATE()),0)) AND DAY(birth_dt)<birth_dt<DAY(DATEADD(wk,DATEDIFF(wk,0,GETDATE())+1,0))[/code]
Go to Top of Page

swathigardas
Posting Yak Master

149 Posts

Posted - 2008-12-08 : 03:57:16
Thanks a Lot Vishakh For your Query. But i need the birthday's falling in this current week meaning 7th December 2008 to 13th December 2008. But the Query which you gave is checking from 8th DEcember i.e, Todays's date to 15th December 2008.

Thanks in Advance ...
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-12-08 : 04:32:20
See http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=80709


E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-12-08 : 05:50:19
[code]select e.first_NM,Birth_DT from Temployee e,TEmployee_info ei where e.employee_nbr=ei.employee_nbr and MONTH(birth_dt)= MONTH(GETDATE())
AND DAY(birth_dt)>=DAY(DATEADD(wk,DATEDIFF(wk,0,GETDATE()),-1)) AND DAY(birth_dt)<birth_dt<DAY(DATEADD(wk,DATEDIFF(wk,0,GETDATE())+1,-1))[/code]
Go to Top of Page

swathigardas
Posting Yak Master

149 Posts

Posted - 2008-12-08 : 09:06:16
Thanks Vishakh and Peso for the Solutions
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-12-08 : 09:20:26
Welcome
Go to Top of Page

Sweetynewb
Starting Member

1 Post

Posted - 2012-08-14 : 03:23:32
Given query worked great for me. Thanks a lot.
But for the week whose 2/3 dates come under previous month and current month, it does not work. Any solution for this?
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-08-14 : 15:00:50
can you elaborate issue giving an example?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

lionofdezert
Aged Yak Warrior

885 Posts

Posted - 2012-08-24 : 18:07:19
SQL Server: Query to Find Upcoming birthdays for Current Week
http://connectsql.blogspot.com/2012/08/sql-server-query-to-find-upcoming.html

--------------------------
http://connectsql.blogspot.com/
Go to Top of Page
   

- Advertisement -