Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 how to subtract days from the given format

Author  Topic 

madpop1
Starting Member

4 Posts

Posted - 2014-12-02 : 05:04:58
hi guys can tell me " how to subtract days from the given format "
format : Mon, 03 Nov 2014 14:10:00 GMT and it is in varchar(50) uunder dates column the data is inserted

mandm
Posting Yak Master

120 Posts

Posted - 2014-12-02 : 07:12:16
Assuming the format stays consistent with your example the following should work.

DECLARE @DateString VARCHAR(50)
SET @DateString = 'Mon, 03 Nov 2014 14:10:00 GMT'

SELECT DATEADD(DAY, -2, CONVERT(DATETIME, SUBSTRING(@DateString, 6, LEN(@DateString) - 9))) AS DateAndTime
Go to Top of Page
   

- Advertisement -