Click here to Skip to main content
15,888,802 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
hi, i want to
select data from database between two dates where date datatype is datetime.

please reply
Posted
Comments
Zoltán Zörgő 18-Oct-12 3:12am    
Good for you. I suppose you wanted to formulate a question. This is not a question, this is a wish. But we are not Santa...

try these queries
SQL
select * from [tablename] where [datefrom] between [dateto]

OR
SQL
select * from [tablename] where convert(datetime,[datefrom],103)>'"+[valuefrom]+"' and convert(datetime,[dateto],103)<'"+[valueto]+"'


Thanks
 
Share this answer
 
Comments
[no name] 18-Oct-12 5:28am    
perfct 5
Look at this MSDN documentation page[^] section D.
 
Share this answer
 
Try this in where condition
SQL
WHERE ((CAST(FLOOR(CAST(SearchDate AS FLOAT)) AS DATETIME) 
	BETWEEN 
	CAST(FLOOR(CAST(@FromDate AS FLOAT)) AS DATETIME)
	AND CAST(FLOOR(CAST(@ToDate AS FLOAT)) AS DATETIME))

from above query you can check difference till dd/mm/yyyy hh:mm:ss
 
Share this answer
 
v2
hi
check out the query
SQL
SELECT * FROM TableName where datetime between
to_date('01-oct-2012,'mm/dd/yyyy') and
to_date('30-oct-2012','mm/dd/yyy')
order by datetime DESC;


or
SQL
select column1, column2 from tablename where
convert(char(20),columnname,105) between '21-10-2012' and '19-10-2012';
 
Share this answer
 
Comments
[no name] 18-Oct-12 5:29am    
5
SQL
select * from `tablename` where `datetime` >= '2012-01-01 00:00:00' and `datetime` <= '2012-12-31 23:59:59';
 
Share this answer
 
Comments
[no name] 18-Oct-12 5:29am    
5

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