Hi,
I want to convert 'Wed Sep 13 2023 00:00:00 GMT+0530 (India Standard Time)' to datetime in sql. the requirement is to compare this date with Getdate(). Please suggest a way to convert this to datetime
Hi,
I want to convert 'Wed Sep 13 2023 00:00:00 GMT+0530 (India Standard Time)' to datetime in sql. the requirement is to compare this date with Getdate(). Please suggest a way to convert this to datetime
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Ali BenchaabanRank #925 · 2.2K reputationPosted Sep 19, 2023, 5:23 AM EDT
DECLARE @inputString NVARCHAR(100) = 'Wed Sep 13 2023 00:00:00 GMT+0530'; DECLARE @convertedDateTime DATETIME; SET @convertedDateTime = CONVERT(DATETIME, SUBSTRING(@inputString, 5, 20), 9); IF @convertedDateTime > GetDate() BEGIN PRINT 'your message here'; END ELSE BEGIN PRINT 'your message here'; ENDAjay KumarRank #56 · 29K reputationPosted Sep 25, 2023, 8:00 AM EDT
DECLARE @inputString NVARCHAR(MAX) = 'Wed Sep 13 2023 00:00:00 GMT+0530 (India Standard Time)' -- Extract relevant parts from the input string DECLARE @day NVARCHAR(3) = SUBSTRING(@inputString, 1, 3) DECLARE @month NVARCHAR(3) = SUBSTRING(@inputString, 5, 3) DECLARE @dayOfMonth INT = CAST(SUBSTRING(@inputString, 9, 2) AS INT) DECLARE @year INT = CAST(SUBSTRING(@inputString, 12, 4) AS INT) DECLARE @time NVARCHAR(8) = SUBSTRING(@inputString, 17, 8) -- Create a datetime value DECLARE @formattedDate NVARCHAR(30) = CONCAT(@month, ' ', @dayOfMonth, ', ', @year, ' ', @time) DECLARE @convertedDate DATETIME = CONVERT(DATETIME, @formattedDate, 0) -- Compare with GETDATE() SELECT @convertedDate AS ConvertedDate WHERE @convertedDate = GETDATE()