0

I want to know how to achieve the following: I want to convert a varchar to a date format but so far I'm not very successfull...

My date (varchar) looks something like this: 02-02-2012 11:48 AM
And I want to convert it to the following this: dd-mm-yyyy

To be able to use the BETWEEN clause in the end.

I have the following script but it is not correct so any help regarding this will help me a lot!

SELECT Con_Consult_Date
FROM Consultation
WHERE CONVERT(varchar(30), Con_Consult_Date, 105) BETWEEN '01-01-2013' AND '31-12-2013'
GO
1
Contributor
1
Reply
5
Views
2 Years
Discussion Span
Last Post by Joemeister
0

NVM people. I got the solution:

SELECT Con_Consult_Date
FROM Consultation
WHERE CAST(CONVERT(CHAR(10), CONVERT(DATETIME, Con_Consult_Date, 105), 101) AS DATE) 
BETWEEN CAST(CONVERT(CHAR(10), CONVERT(DATETIME, '01-01-2013', 105), 101) AS DATE) 
AND CAST(CONVERT(CHAR(10), CONVERT(DATETIME, '31-12-2013', 105), 101) AS DATE)
GO
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.