Comparing Dates .... Problem Continuation
Sorry i forgot to mention in the previous post. Within the SP i am using the BETWEEN clause for comparing dates. Like :-
Where [Date] Between @DateFrom And @Dateto.
Sanjay.
------------
Sanjay at 7/10/01 2:34:37 PM
How do i compare 2 dates without comparing their Time portions. I have a Datetime column in my table which for example has values :-
6/6/2001 7:23:42 PM
6/6/2001 8:01:08 PM and so on....
I have a Stored Procedure in which i am trying to fetch values from this table. The SP has 2 DateTime parameters @DateFrom and @Dateto. This SP is called from a Web page. On the Web Page the user just enters mm/dd/yyyy values for the 2 Date parameters. Therefore the Time portions defaults to 12:00 AM. So when the user passes 6/6/2001 as Date From and 6/6/2001 as Date To values, he doesn't get back the 2 records mentioned above since the Time portion makes the 2 records fall out of the date range.
Is there a way to just do a comparison on the Date portions i.e. give me all the records for 6/6/2001 irrespective of the time. I don't wan't to do individual comparisons for Day then Month and then Year.
Thanks
Sanjay.
Comparing Dates .... Problem Continuation (reply)
You could look at and use 'convert or cast'
these instructions give a subset of the full stored datetime.
Choose the 'style' your application needs.
------------
Sanjay at 7/10/01 2:36:58 PM
Sorry i forgot to mention in the previous post. Within the SP i am using the BETWEEN clause for comparing dates. Like :-
Where [Date] Between @DateFrom And @Dateto.
Sanjay.
------------
Sanjay at 7/10/01 2:34:37 PM
How do i compare 2 dates without comparing their Time portions. I have a Datetime column in my table which for example has values :-
6/6/2001 7:23:42 PM
6/6/2001 8:01:08 PM and so on....
I have a Stored Procedure in which i am trying to fetch values from this table. The SP has 2 DateTime parameters @DateFrom and @Dateto. This SP is called from a Web page. On the Web Page the user just enters mm/dd/yyyy values for the 2 Date parameters. Therefore the Time portions defaults to 12:00 AM. So when the user passes 6/6/2001 as Date From and 6/6/2001 as Date To values, he doesn't get back the 2 records mentioned above since the Time portion makes the 2 records fall out of the date range.
Is there a way to just do a comparison on the Date portions i.e. give me all the records for 6/6/2001 irrespective of the time. I don't wan't to do individual comparisons for Day then Month and then Year.
Thanks
Sanjay.
Comparing Dates .... Problem Continuation (reply)
Hi, Sanjay -
Try:
"WHERE convert(datetime, convert(char, [date], 101)) Between @DateFrom and @DateTo"
The convert to character (with style 101) removes the time portion and then converting back to datetime makes it 12:00AM - just like the parameters being passed in.
Hope this helps.
Paul
------------
Sanjay at 7/10/01 2:36:58 PM
Sorry i forgot to mention in the previous post. Within the SP i am using the BETWEEN clause for comparing dates. Like :-
Where [Date] Between @DateFrom And @Dateto.
Sanjay.
------------
Sanjay at 7/10/01 2:34:37 PM
How do i compare 2 dates without comparing their Time portions. I have a Datetime column in my table which for example has values :-
6/6/2001 7:23:42 PM
6/6/2001 8:01:08 PM and so on....
I have a Stored Procedure in which i am trying to fetch values from this table. The SP has 2 DateTime parameters @DateFrom and @Dateto. This SP is called from a Web page. On the Web Page the user just enters mm/dd/yyyy values for the 2 Date parameters. Therefore the Time portions defaults to 12:00 AM. So when the user passes 6/6/2001 as Date From and 6/6/2001 as Date To values, he doesn't get back the 2 records mentioned above since the Time portion makes the 2 records fall out of the date range.
Is there a way to just do a comparison on the Date portions i.e. give me all the records for 6/6/2001 irrespective of the time. I don't wan't to do individual comparisons for Day then Month and then Year.
Thanks
Sanjay.
Comparing Dates .... Problem Continuation (reply)
Thanks Paul. It worked.
------------
Paul at 7/10/01 2:44:54 PM
Hi, Sanjay -
Try:
"WHERE convert(datetime, convert(char, [date], 101)) Between @DateFrom and @DateTo"
The convert to character (with style 101) removes the time portion and then converting back to datetime makes it 12:00AM - just like the parameters being passed in.
Hope this helps.
Paul
------------
Sanjay at 7/10/01 2:36:58 PM
Sorry i forgot to mention in the previous post. Within the SP i am using the BETWEEN clause for comparing dates. Like :-
Where [Date] Between @DateFrom And @Dateto.
Sanjay.
------------
Sanjay at 7/10/01 2:34:37 PM
How do i compare 2 dates without comparing their Time portions. I have a Datetime column in my table which for example has values :-
6/6/2001 7:23:42 PM
6/6/2001 8:01:08 PM and so on....
I have a Stored Procedure in which i am trying to fetch values from this table. The SP has 2 DateTime parameters @DateFrom and @Dateto. This SP is called from a Web page. On the Web Page the user just enters mm/dd/yyyy values for the 2 Date parameters. Therefore the Time portions defaults to 12:00 AM. So when the user passes 6/6/2001 as Date From and 6/6/2001 as Date To values, he doesn't get back the 2 records mentioned above since the Time portion makes the 2 records fall out of the date range.
Is there a way to just do a comparison on the Date portions i.e. give me all the records for 6/6/2001 irrespective of the time. I don't wan't to do individual comparisons for Day then Month and then Year.
Thanks
Sanjay.