Avatar of APD Toronto
APD Toronto
Flag 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.
Microsoft SQL Server 2008SQL

Avatar of undefined
Last Comment
lcohan

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
lcohan

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
lcohan

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
Your help has saved me hundreds of hours of internet surfing.
fblack61