Hello everyone, I am going to share the query
sample for convert string date-time to date-time and also use of various types
of convert in SQL.
Table of Contents
1.
Query for convert string DateTime to DateTime type
2.
Query for convert GETDATE to DATE type
3.
Query for convert GETDATE to string DATE
type
4.
Query for convert GETDATE to DateTime
type
5.
Query for convert GETDATE to string DateTime
type
6.
Query for convert GETDATE to string dateTime2
type
The Query detail as given below.
DECLARE @DATEIME DATETIME = '10/01/2016 12:25pm'
SELECT CONVERT(DATETIME, @DATEIME) as DATETIME
SELECT CONVERT (DATE, GETDATE()) as Date
SELECT CONVERT(VARCHAR(10), GETDATE(), 113) as Date
SELECT CONVERT (DATETIME, GETDATE()) as DateTime
SELECT CONVERT (DATETIME2, GETDATE()) as DateTime2
SELECT CONVERT(DATETIME, CONVERT(VARCHAR(10), GETDATE(), 112)) as DateTime
The output as given below image