I have a table with two columns.
two columns are of datetime datatype
I have two records in the table
2/1/2004 12/30/2004
2/1/2004 6/30/2004
I need to retreive the record from the range 2/1/2004 to 7/15/2004. When I
use the < and > symbol. it is not working with the datetime feild.
Can anyone help me how to retreive those records in the specified date range
.
Thanks in Advance
- VigneshUse the BETWEEN operator.
ex. WHERE somedate BETWEEN '02/01/04' AND '07/15/04'
Jeff Lynch
"A BizTalk Enthusiast"
http://dotnetjunkies.com/WebLog/jlynch/
"Vignesh" <Vignesh@.discussions.microsoft.com> wrote in message
news:F248183B-DC8D-4D43-8198-BB3849864193@.microsoft.com...
>I have a table with two columns.
> two columns are of datetime datatype
> I have two records in the table
> 2/1/2004 12/30/2004
> 2/1/2004 6/30/2004
> I need to retreive the record from the range 2/1/2004 to 7/15/2004. When I
> use the < and > symbol. it is not working with the datetime feild.
> Can anyone help me how to retreive those records in the specified date
> range.
> Thanks in Advance
> - Vignesh
>|||First, does both colomns need to be within the date range, or just one?
Using the follow DDL's
create table lookup(date1 datetime, date2 datetime)
insert lookup values ('2004-2-1','2004-12-30')
insert lookup values ('2004-2-1','2004-6-30')
--If both between dates
select *
from lookup
where date1 between '2004-2-1' and '2004-7-15'
and date2 between '2004-2-1' and '2004-7-15'
--If either between dates
select *
from lookup
where date1 between '2004-2-1' and '2004-7-15'
or date2 between '2004-2-1' and '2004-7-15'|||BETWEEN works well with one column and with two dates.
but I have only one date for both the column.
col1 > somedate1 and col2 < somedate2
having the column name as startdate and enddate to get more clarity.
I need to retreive the records from the specified startdate till the
specified end date.
Can this be acheived?
Thanks
- Vignesh.
"Jeff Lynch" wrote:
> Use the BETWEEN operator.
> ex. WHERE somedate BETWEEN '02/01/04' AND '07/15/04'
> --
> Jeff Lynch
> "A BizTalk Enthusiast"
> http://dotnetjunkies.com/WebLog/jlynch/
>
> "Vignesh" <Vignesh@.discussions.microsoft.com> wrote in message
> news:F248183B-DC8D-4D43-8198-BB3849864193@.microsoft.com...
>
>|||If you try to represent a date as a string and leave off the hh:mm:ss
portion, it is assumed 00:00:00. So, 12/30/2004 03:30pm is not between
2/1/2004 and 12/30/2004, becuase it is greater than "12/30/2004".
"Vignesh" <Vignesh@.discussions.microsoft.com> wrote in message
news:F248183B-DC8D-4D43-8198-BB3849864193@.microsoft.com...
> I have a table with two columns.
> two columns are of datetime datatype
> I have two records in the table
> 2/1/2004 12/30/2004
> 2/1/2004 6/30/2004
> I need to retreive the record from the range 2/1/2004 to 7/15/2004. When I
> use the < and > symbol. it is not working with the datetime feild.
> Can anyone help me how to retreive those records in the specified date
range.
> Thanks in Advance
> - Vignesh
>|||
hi u can try
this one
suppose u want to retrive record between 02/02/2005 to 04/02/2005
select *
from tablename
where
datediff(dd,02/02/2005,ur_datetime_column)>=0
and
datediff(dd,ur_datetime_column,04/02/2005)>=0
Message posted via http://www.webservertalk.com
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment