| |
|
Different method to convert string to date explicitly? Question Posted on 22 Aug 2022 Home >> DataBase >> SQL Query >> Different method to convert string to date explicitly? |
Different method to convert string to date explicitly?
When we sayabout the explicit conversion which is done by using some functions or tools. Below are the 3 function which helps to convert string explicitly:-
(1)CAST()
(2)CONVERT()
(3)PARSE()
(1)CAST():-It is most basic conversion function provided by SQL Server. This function will helps to tries to convert given value to a specified data type. Below is the syntax given below:-
select cast('12/01/2019' as date) as strToDate, CAST(GETDATE() as VARCHAR(50)) as DateToStr
(2)CONVERT():-CONVERT() function is more advanced than CAST() since the conversion style can be specified. And this function takes 3 arguments as given below:-
(i)Require data type
(ii)Input value
(iii)Style number(which is optional)
And below is the syntax for CONVERT()
SELECT CONVERT(DATETIME,'19/12/2019',103)
(3)PARSE():-PARSE() is SQL CLR function that use .Net framework Parse() function. PARSE() syntax is as follows:-
Select PARSE('19/12/2020' as date USING 'AR-LB') | |
|
|
|
|