473,387 Members | 1,456 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Return Only Sat/Sun dates in a date range

Hi, I see alot of examples of returning the count of but was wondering how I return the actual dates of the weekends in a particular range. Can anyone provide an example.
Nov 14 '11 #1
2 2006
ck9663
2,878 Expert 2GB
What do you have so far?
Nov 15 '11 #2
Here is a snipet of code I use to create a calendar table. I modified it to return only weekends between @StartDate and @EndDate

Expand|Select|Wrap|Line Numbers
  1.  IF (EXISTS(select * from tempdb..sysobjects where name LIKE '#Calendar%'))
  2.     drop table #Calendar
  3.  
  4.  
  5. create table #Calendar
  6.  (
  7.  DOW varchar(10),
  8.  #CalendarDate datetime,
  9.  Holiday Bit default 0,
  10.  Workday Bit default 0,
  11.  Weekend Bit default 0
  12.  )
  13. declare @StartDate date
  14. declare @EndDate date
  15. set @StartDate = '1/1/2011'
  16. set @EndDate = '12/31/2012'
  17.  
  18. while @StartDate <= @EndDate
  19. begin
  20. Insert into #Calendar
  21. (
  22.  #CalendarDate
  23. )
  24. select
  25. @StartDate
  26. set @StartDate = dateadd (dd, 1, @StartDate)
  27. end
  28.  
  29. -- Set the day of week name (DOW)
  30. update 
  31. #Calendar 
  32. set
  33. DOW = datename(dw,#CalendarDate)
  34. go
  35.  
  36.  
  37. -- Identify Weekends
  38. SELECT
  39. DATENAME(dw,#CalendarDate), #CalendarDate
  40. FROM #Calendar
  41. where datename(dw,#CalendarDate) in ('Saturday','Sunday')
  42. go
  43.  
  44.  
Nov 30 '11 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Dennis M. Marks | last post by:
What is the maximum valid date range for the date(yyyy,mm,dd) function. -- Dennis M. Marks http://www.dcs-chico.com/~denmarks/ Replace domain.invalid with dcsi.net -----= Posted via...
4
by: Mark | last post by:
Hi I have been trying to convert the week number to a range of dates that I can use. It should be fairly simple for you guru's out there but for us mere mortals it is beyond our grasp. I know...
2
by: Terry | last post by:
I have a database that I would like to query for a specific date range. I want to create a report based on this query that will pull any records from the last 7 days. Is this possible? Can...
2
by: Sara | last post by:
I have followed instructions on the http://allenbrowne.com/tips.html for limiting a report to a date range. At the bottom there is a note that says You will end up using this form for all sorts...
10
by: RoadRunner | last post by:
Hi, I have a employee vacation database that has a vacation table that has the employee name, pay week and date of vacation. I have another lookup table with pay week code and date range for the...
3
by: rugger81 | last post by:
I am currently working in the sql server 2000 environment and I want to write a function to pull all dates within a given date range. I have created several diferent ways to do this but I am...
0
by: rdemyan via AccessMonster.com | last post by:
I have a need to highlight a date range in a bar chart. If the "highlighting" is accomplished by changing the bar column color for the specific months in the date range, that would be great. ...
5
by: jrodcody | last post by:
Hello: I am trying to create multiple records in a table named tblTravel based on the input of a date range in two form controls. The inputs for the form are LastName, TravelDate, EndDate,...
3
by: Deano | last post by:
The short version; In short, given one date range (start and end dates) how can I find the period that overlaps with another date range? The long version; I have knocked up a little application...
3
by: Vinda | last post by:
Hi Bytes, Using a previous question as a base Access 2000 Inserting multiple rows based on a date range. I also wanted to insert multiple rows into a table according to a date range supplied by a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.