I have a TEXT in this format 31/10/15
.
How do I convert this into a DATE format?
As I need to let the user search from data using a date range.
example: From 15/7/13
to 31/10/15
Or is there a way to so without converting to date?
I have a TEXT in this format 31/10/15
.
How do I convert this into a DATE format?
As I need to let the user search from data using a date range.
example: From 15/7/13
to 31/10/15
Or is there a way to so without converting to date?
You can use CONVERT()
for this:
DECLARE @d VARCHAR(50) = '31/10/50'
SELECT CONVERT(DATE, @d,3)
Note that with a 2-digit year SQL Server will make the year start with '19' for 50 and up, and 49 and below will be '20'
Storing as a DATE
field will allow easier comparisons, otherwise you'll have to perform this conversion at each step.
Use CONVERT
; example:
SELECT [Date] = CONVERT(date, '31/10/15', 3);
And yes, it's possible to search dates in the same format as the examples you provide, but don't do that – use the proper data types in both your queries and your table columns.