satheesh babu

satheesh babu

  • NA
  • 128
  • 312.6k

varchar to date conversion in sql server 2005

Dec 24 2008 8:34 AM
Hi all,


i have a date column in my table with varchar(50), and i stored the values from front end with format dd/mm/yyyy.

and i want to compare the dates like membership_expires between date1 and date2 its giving wrong result set.

so i am converting all the variables and columns into date format.

Below is my code to convert

select membership_expires,count(
membership_expires) from membershipregistration
where convert(datetime,membership_expires,103) between
(select(convert(datetime,@fromdate,103))) and
(select(convert(datetime,@todate,103)))

group by Membership_Expires

and in the above i a providing @fromdate ,@todate from front end.

but its giving below error

The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.

Please help me on this error and one more thing is if i store dates in dd-mm-yyyy format its working fine instead of dd/mm/yyyy

thank you....

Answers (1)