Search Between 2 dates

Posted by Vijayar under C# on 8/11/2011 | Points: 10 | Views : 2558 | Status : [Member] | Replies : 3
Hi
I have one column called date in database,but in front end iam using 2 ajaxdate pickers and searching for a record
i am writing the query like this,i want to know whether it is correct or not
SELECT * from table where Date between ='" + txtfromdate.Text + "and" +txttodate +"'";

vijaya


Responses

Posted by: Mcadeepuraj on: 8/11/2011 [Member] Starter | Points: 25

Up
0
Down
in database term, only date format is treated, textbox behaves as string, so first we have to change textbox string in dateformat.
the best option to convert textbox in to date is format(textbox1.text, "dd MMM yyyy"). it will work
now your query should be

SELECT * from table where Date between ='" + Format(txtfromdate.Text,"dd MMM yyyy") + "and" +format(txttodate.text,"dd MMM yyyy") +"'";



Deepak Kumar

Vijayar, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Alok on: 8/12/2011 [Member] Starter | Points: 25

Up
0
Down
date between convert(datetime,date1,103) and convert(datetime,date2,103)

Thanks & Regards,
Alokssm

Vijayar, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Alok on: 8/12/2011 [Member] Starter | Points: 25

Up
0
Down
convert(datetime,date,103) between convert(datetime,date1,103) and convert(datetime,date2,103)



Thanks & Regards,
Alokssm

Vijayar, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response