Home Convert a Varchar/String with day name to Date in Sql Server
Reply: 1

Convert a Varchar/String with day name to Date in Sql Server

Akshay Mishra
1#
Akshay Mishra Published in 2018-01-12 07:42:07Z

I have a string Sunday, November 19, 2017 in Varchar.

How can I convert this to Date Format - dddd, MMMM, yyyy?

gotqn
2#
gotqn Reply to 2018-01-12 08:11:21Z

Are you looking for this:

DECLARE @MyDate VARCHAR(32) = 'Sunday, November 19, 2017';

SELECT CONVERT(VARCHAR(32), CAST(SUBSTRING(@MyDate, CHARINDEX(',', @MyDate) + 2, 32) AS DATETIME2), 105);  -- 19-11-2017

or this:

SELECT FORMAT(CAST(SUBSTRING(@MyDate, CHARINDEX(',', @MyDate) + 2, 32) AS DATETIME2), 'dddd, MMMM, yyyy'); -- Sunday, November, 2017
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.249589 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO