C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Forums » .NET » SQL Server »

Date between


Posted Date: 05 Jul 2009      Posted By: harish      Member Level: Silver     Points: 1   Responses: 11



i want to fetch a row data based on 2 dates...
with query pls help me to get the query





Responses

Author: Abhinav Dawra    05 Jul 2009Member Level: GoldRating: 2 out of 52 out of 5     Points: 2

Hi,

You can use one of the 2 approaches:

select * from <tablename> where <datecolumn> between date1 and date2;

OR

select * from <tablename> where <datecolumn> >= date1 and <datecolumn> <= date2;

(The second query can be used for inclusion/exclusion of boundary values)

Thanks,
Abhinav
Please rate if you find this answer useful



Author: ABitSmart    05 Jul 2009Member Level: DiamondRating: 2 out of 52 out of 5     Points: 2

How is this different from your previous question you just posted? You did see you got the same answer from the same users, so there's no point repeating the question.

Please do not post multiple posts for the same question.



Author: Ashok    05 Jul 2009Member Level: GoldRating: 2 out of 52 out of 5     Points: 2

hi,
try this query....

select * from [tablename] where dateadd(dd,datediff(dd,0,[columnname]),0) between dateadd(dd,datediff(dd,0,'31-Mar-2009'),0) and dateadd(dd,datediff(dd,0,'19-May-2009'),0)

Please rate this post, if it is useful for you.

Thanks & Regards
Ashok



Author: Deepika Haridas    05 Jul 2009Member Level: DiamondRating: 2 out of 52 out of 5     Points: 2

Hi,

Just need to write

select col1,col2 from [tablename] where date between date1 to date2;

Based on the date format needed convert it.



Thanks & Regards,
Deepika
Editor

If U want to shine like a SUN..First U have to burn like the SUN!!
Need a Guide? Join my mentor program..



Author: Williams    05 Jul 2009Member Level: GoldRating: 2 out of 52 out of 5     Points: 2

Hi,

If u want only between dates then the query is


select <columns> from <table> where convert(char(8),<date column>,112) between convert(char(8),<date1>,112) and convert(char(8),<date2>,112)


If u want time part also then the query is

select <columns> from <table> where convert(char(16),<date column>,120) between convert(char(16),<date1>,120) and convert(char(16),<date2>,120)



Author: Raj    06 Jul 2009Member Level: GoldRating: 2 out of 52 out of 5     Points: 2

Hi,

SELECT columns FROM table WHERE dateColumn BETWEEN startDate AND endDate

Thanks,
Raj



Author: Krishnaveni    06 Jul 2009Member Level: GoldRating: 2 out of 52 out of 5     Points: 2

select *
from
table t
WHERE convert(datetime,CONVERT(VARCHAR,t.Startdate,101))
BETWEEN convert(datetime,CONVERT(VARCHAR,'01/02/2009',101))
AND convert(datetime,CONVERT(VARCHAR,'05/04/2009',101))



Author: ketha    06 Jul 2009Member Level: SilverRating: 2 out of 52 out of 5     Points: 2

select * from TableName where ColumnName >= FromDate and ColumnName <= ToDate


Author: MANIKANDAN    06 Jul 2009Member Level: SilverRating: 2 out of 52 out of 5     Points: 2

select datecolumn from datetable where datecolumn between startdate and todate


Author: Devendra    06 Jul 2009Member Level: GoldRating: 2 out of 52 out of 5     Points: 2

select col1,col2 from [tablename] where date between date1 to date2;


Author: Rajesh    07 Jul 2009Member Level: BronzeRating: 2 out of 52 out of 5     Points: 2

Hi,

use this if u want the result inbetween the two dates

SELECT columns FROM table WHERE dateColumn BETWEEN startDate AND endDate

use this if u want the result two particulars dates

SELECT columns FROM table WHERE dateColumn in (date1, date2)



Post Reply

 This thread is locked for new responses. Please post your comments and questions as a separate thread.
If required, refer to the URL of this page in your new post.


Next : How to set password for mysql
Previous : How to set
Return to Discussion Forum
Post New Message
Category: SQL Server

Related Messages



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use