Bishoy Ezzat Bishoy Ezzat - 1 year ago 70
SQL Question

how to preview a date - 60 days in a specific date format in sql?

I am trying to preview a date before 60 days of a specific date in this date format: 03-Mar-2013 .. how can I subtract 60 days from this date ... I used this code but it didn't work as it subtract from the days only and it didn't subtract from the month or the year:

Select LTRIM(DAY(@date - 60))+'-'+CONVERT(varchar(3), DATENAME(MONTH,@date))+'-'+LTRIM(YEAR(@date))

Any help ?

Answer Source

try this-

select REPLACE(CONVERT(VARCHAR(11), DATEADD(dd, -60, cast('03-Mar-2013' as date)), 106), ' ', '-') AS [DD-Mon-YYYY]
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download