Query to Convert VARCHAR to DATETime and add months in SQL Server

Last Reply 5 months ago By dharmendr

Posted 5 months ago

tblLOgin: I have table like this 

UserID  Pass         SDate             

abc     sky@abc     19.10.2018

sky      abc@sky     21.10.2018     

I want to get output like this 

=====================================

UserID  Pass         SDate             NextDate

abc     sky@abc     19.10.2018      19.11.2018

sky      abc@sky     21.10.2018      21.11.2018

 

You are viewing reply posted by: dharmendr 5 months ago.
Posted 5 months ago

Hi smile,

Refer below sample query.

SQL

DECLARE @Test AS TABLE(UserID VARCHAR(10),Pass VARCHAR(50),SDate VARCHAR(10))
INSERT INTO @Test VALUES('abc','sky@abc','19.10.2018')
INSERT INTO @Test VALUES('sky','abc@sky','21.10.2018')
SELECT UserID,Pass,SDate,CONVERT(VARCHAR, DATEADD(MONTH,1,CONVERT(DATETIME, SDate, 103)), 104) NextDate FROM @Test

Output

UserID Pass SDate NextDate
abc sky@abc 19.10.2018 19.11.2018
sky abc@sky 21.10.2018 21.11.2018