| 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 |
 |
|
|
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] |
 |
|
|
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 ... |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
|
|
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] |
 |
|
|
swathigardas
Posting Yak Master
149 Posts |
Posted - 2008-12-08 : 09:06:16
|
| Thanks Vishakh and Peso for the Solutions |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-12-08 : 09:20:26
|
| Welcome |
 |
|
|
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? |
 |
|
|
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 MVPhttp://visakhm.blogspot.com/ |
 |
|
|
lionofdezert
Aged Yak Warrior
885 Posts |
|
|
|