Click here to Skip to main content
15,886,137 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
any 1 help me to write sql to print dates between two given dates. ie two dates are given for example (01-12-2006 and 05-12-2006) and want to print dates like 01-12-2006
02-12-2006
03-12-2006
04-12-2006
05-12-2006
thanks in advance
Posted
Comments
Pandiarajan A 17-Feb-14 1:18am    
sorry i am not using SQL query. i have a simple program one text box have one date and another text box have another date values. my result shows in listbox how to get it? pls help me

Assuming you are using sql server:
SQL
SELECT * FROM table1
WHERE CONVERT(date, nameofdatefield, 105) BETWEEN '01-12-2006' and '05-12-2006'
 
Share this answer
 
v2
try this use between operator:-

SQL
SELECT column_name(s)
FROM table_name
WHERE column_name BETWEEN value1 AND value2;


eg:-
SQL
SELECT dates
FROM orders
WHERE order_date BETWEEN TO_DATE ('2003/01/01', 'yyyy/mm/dd')
AND TO_DATE ('2003/12/31', 'yyyy/mm/dd');


refer:-
http://www.w3schools.com/sql/sql_between.asp[^]
 
Share this answer
 
v2
SQL
Declare @StartDate Date = '12/01/2006'
Declare @EndDate Date = '12/05/2006'
Declare @CurrDate Date
set @CurrDate = @StartDate

WHILE @CurrDate <= @EndDate
BEGIN

    PRINT @CurrDate
    SET @CurrDate = DATEADD(DD,1,@CurrDate)
END
 
Share this answer
 
v2
May be this ids useful 4 u......manipulate this code according to your need


SQL
declare @fromDate Date,@toDate Date
set @fromDate='12-01-2006'
set @toDate='12-05-2006'

;WITH sample AS (
			SELECT CAST(@fromDate AS DATETIME) AS Dates
			UNION ALL
			SELECT DATEADD(dd, 1, Dates)
			FROM sample s
			WHERE DATEADD(dd, 1, Dates) <= CAST(@toDate AS DATETIME))
			select * from sample
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900