I have the following problem. I wrote a query to get the date of an order in c#:
QueryDate = string.Format("(Order.Begin>= '{0}' and Order.End<= '{1}')", BeginDate, EndDate);
The problem is my SQL Server table columns, ‘Begin’ and ‘End’, are varchar columns and I want to keep them this way. They are saved as ’12-4-2012′ for example.
Now I want to get the dates between say ’12-4-2012′ and ’19-4-2012′. But the result is everything between ’12’ and ’19’ with the first 2 digits. So the results also include ’14-8-2011′ for example.
Is there a way retrieve only the dates between ’12-4-2012′ and ’19-4-2012′ with a string column?
I think you can convert the Begin and Order columns into DateTime format something like this:
QueryDate = string.Format("(convert(datetime, Order.Begin, 105) >= @startdate and convert(datetime, Order.End, 105)<= @enddate;"And then add he @startdate, and @enddae parameters…