I am trying to select the first day of the month 3 months before the current date.
so for example if the current date was: '2015-11-08' my result would want to be: '2015-08-01'
I would prefer if this was in yyyy-mm-dd format.
I tried this to start with but had no luck:
SELECT DATEADD(dd, -DAY('2015-09-01') + 1, @today)
I have tried numerous things but cannot seem to crack it, any advice or help would be appreciated. Thank you in advance
2条答案
按热度按时间wh6knrhe1#
The logic is simple:
In SQL Server:
For the current date:
And as a string:
pbpqsu0x2#
select dateadd(month, -3, dateadd(day, -2, '2014-09-03'))