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

Hey! I'm Anil Singh. I author this blog. I'm Active Blogger, Programmer. I love learning new technologies, programming, blogging and participating the forum discussions more...
My Blogs - http://www.code-sample.com and http://www.code-sample.xyz
My Books - Buy Books Online at Best Prices

You Might Also Like
Post a Comment
www.code-sample.com/. Powered by Blogger.