How do I convert a string to a date type in SQL Server 2008 R2?
My string is formatted dd/mm/yyyy
I tried this
SELECT CAST('01/08/2014' AS DATE)
But that does the cast in mm/dd/yyyy format.
You need the convert function, where you can specify a format code:
select convert(datetime, '01/08/2014', 103)
The 103 means dd/mm/yyyy. See the docs.
Dateformat.
SET DATEFORMAT DMY ;
SELECT cast('01/08/2014' as date) ;
Convert.
SELECT convert(date, '01/08/2014', 103 ) ;
And for completeness, SQL Server 2012 and later has the following.
SELECT parse('01/08/2014' as date using 'en-NZ' ) ;
TO_DATE function in oracle is used to convert any character to date format.
for example :
SELECT to_date ('2019/03/01', 'yyyy/mm/dd')
FROM dual;
CONVERT function in SQL SERVER is used to converts an expression from one datatype to another datatype.
for example:
SELECT CONVERT(datetime, '01/08/2014', 103) date_convert;
I hope this will help you.
convert().