Function to Convert String to Date in SQL Server

The SQL Server has inbuilt function to convert string to date. It can be done using CAST/CONVERT as shown below

DECLARE @stringdate varchar(100),
@cast_dt datetime,
@conver_dt datetime
SET @stringdate='09/25/2014'


SET @cast_dt=CAST(@stringdate AS datetime) 
SET @conver_dt=CONVERT(datetime, @stringdate, 110) 
SELECT 
	@stringdate As Date_as_String,
	@cast_dt AS cast_string_to_date,
	@conver_dt AS convert_string_to_Date

sql server function to convert string to date

There are other formats available in convert function. To get more detail refer to http://msdn.microsoft.com/en-us/library/ms187928.aspx

 

Like us on FaceBook Join the fastest growing SQL Server group on FaceBook

Data Platform Virtual Summit 2020

Subscribe to SQLServerGeeks YouTube channel. If you want more learning content in your inbox, subscribe to SQLServerGeeks Bulletin.

SQLServerGeeks YouTube | SQLServerGeeks Bulletin | SQLServerGeeks Twitter

Leave a Reply

Your email address will not be published. Required fields are marked *