Convert String DateTime to DateTime in SQL Server?

Convert String DateTime to DateTime in SQL Server?

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



ANIL SINGH

Anil Singh is an author, tech blogger, and software programmer. Book writing, tech blogging is something do extra and Anil love doing it. For more detail, kindly refer to this link..

My Tech Blog - https://www.code-sample.com/
My Books - Book 1 and Book 2

Convert String DateTime to DateTime in SQL Server? Convert String DateTime to DateTime in SQL Server? Reviewed by Anil Singh on 6:00 AM Rating: (5)
www.code-sample.com/. Powered by Blogger.
^