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.
Author |
Topic |
cnbhold
Starting Member
43 Posts |
Posted - 2014-07-09 : 19:41:50
|
Have a table called Customers that has a datetime column called Submitted. I need a way to compare the Submitted field against the current date to tell if 5 days have pasted excluding weekends. In the sample data below, the record submitted on 7/2 is the record that should be returned in the query when compared to today's date 7/9.FirstName........LastName.........SubmittedJohn................Miller...............7/01/2014Mary................Smith..............7/02/2014Bob.................Williams..........7/05/2014Angel |
|
ahmeds08
Aged Yak Warrior
737 Posts |
Posted - 2014-07-10 : 05:08:41
|
can you try thisselect * from customerswhere datediff(day,submitted,getdate())=5Javeed Ahmed |
 |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2014-07-10 : 06:00:07
|
do you have a calendar table ? KH[spoiler]Time is always against us[/spoiler] |
 |
|
cnbhold
Starting Member
43 Posts |
Posted - 2014-07-10 : 06:45:33
|
I do not have a calendar tableAngel |
 |
|
mmkrishna1919
Yak Posting Veteran
95 Posts |
Posted - 2014-07-10 : 08:24:29
|
try this for total number of weekdays between two dates. Assuming only are saturday and sunday weekends.Declare@date1 datetime,@date2 datetimeset @date1 = '01July2014'set @date2 = GETDATE()select ( ( (( DATEDIFF(dd, dateadd(dd ,(8-(DATEPART(weekday,@date1))) ,@date1 ) ,@date2) )+1) /7 ) *5)+(DATEPART(weekday,@date2)-1)+(7-DATEPART(weekday,@date1))M.MURALI kRISHNA |
 |
|
cnbhold
Starting Member
43 Posts |
|
|
|
|
|
|