Link to home
Start Free TrialLog in
Avatar of APD Toronto
APD TorontoFlag for Canada

asked on

SQL Date Format

Hello Experts,

I have a SQL SELECT with the following condition:
...AND paymentDate >= '6/20/2012' AND paymentDate <= '7/4/2012'

paymentDate is actually a varchar.

The issue is that my statement does not returns the correct data, and after some digging, I have found that the values in paymentDate are sometimes 2010-04-30 and other times 7/13/2010.

I know that within my SQL SELECT I can take care of it by using I think CAST, but I not exactly sure how to go about doing it.

Any help will be greatly appreciated.
ASKER CERTIFIED SOLUTION
Avatar of lcohan
lcohan
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Also because the column is varchar (bad choice in my opinion for a SQL date type field) you may get lots of errors if user/data input is not validated to be a date.
You could use a statement like below to find all bad dates in that table:

select * from table_name where isdate(paymentDate ) = 0