1
Answer

date conversion problem

satheesh babu

satheesh babu

15y
2.5k
1

 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  or mm/dd/yyyy format its working fine instead of dd/mm/yyyy

please help me

thank you...

Answers (1)