0

If I have 2 days 2013-06-03 and 2013-06-10 as examples, how do I print a list of all the dates between those 2 dates?

For example, the list in this case would be:

2013-06-22
2013-06-23
2013-06-24
2013-06-25
2013-06-26
2013-06-27
2013-06-28
2013-06-29
2013-06-30
2013-07-01
2013-07-02
2013-07-03
2013-07-04
2013-07-05
2013-07-06
2013-07-07
oshirowanen
  • 15,297
  • 82
  • 198
  • 350
  • 2
    This seems to be answered here. http://stackoverflow.com/a/1378788/2429205 let me know if I am wrong. – Iron_Tri Jun 18 '13 at 12:47

2 Answers2

5
DECLARE @Start date = '2013-06-03'
DECLARE @End date = '2013-06-10'

;WITH Dates AS 
(
    SELECT @Start AS [Date]
    UNION ALL
    SELECT DATEADD(DAY, 1, [Date])
    FROM Dates
    WHERE [Date] < @End
)

SELECT [Date] 
FROM Dates
OPTION (MAXRECURSION 0)
Dis Shishkov
  • 657
  • 7
  • 21
-3

I think you are looking for this:

SELECT * FROM TABLE_NAME WHERE DATE_COLUMN_NAME BETWEEN '03-JUNE-2013' AND '10-JUNE-2013'

Jimbo
  • 25,790
  • 15
  • 86
  • 131
Ahmed
  • 452
  • 3
  • 7
  • This pre-supposes that you have a table pre-populated with every date between the two points, which I suspect the OP does not have (but which is not a bad idea). – Jonathan Jun 18 '13 at 12:54