Click here to Skip to main content
15,891,905 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
I have a procedure which takes Start_date and End_Date as input parameters. These parameters are of Date datatype.My query is as follows:

select count(1) from table_name where inspection_date between start_date and end_date;

when I provide values the input parameters as: start_date: 1/1/1800 or 1/1/2000 the query take the start date as 1-jan-00 as result of which I am not getting correct result.

I also tried to convert it into mm/dd/yyyy format using to_date(to_char(start_date,'mm/dd/yyyy),'mm/dd/yyyy') and stored in a variable of type timestamp(6) but still its not giving correct result .

Please let me know how to perform this operation.
Posted

1 solution

SQL
select count(1) 
from table_name 
where inspection_date 
         between 
                to_date(start_date, 'MM/DD/YYYY')) 
         and    to_date(end_date, 'MM/DD/YYYY'));



And make sure you inout the start_date and end_date as :
<br />
'11/01/2008'<br />
'11/01/2010'<br />



Thanks,

Kuthuparakkal
 
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