>>Hi
>>
>>I'm being passed a date via a csv file.
>>
>>I want to insert into my database the previous October 1st of that date minus 4 years.
>>
>>So if my date is 1st January 2011 I'd want the 1st October 2006
>>
>>Any ideas on how I could get that.
>>
>>Thnaks
>
>Do you just want to subtract 4 years from current date?
>
>If so,
>
>declare @PrevDate date
>set @PrevDate = dateadd(year, -4, cast(CURRENT_TIMESTAMP as DATE))
>
>If you always want October 1, then
>
>select CONVERT(datetime,ltrim(year(CURRENT_TIMESTAMP)-4) + '1001') as PreviousDate
Thanks Naomi but Not quite .
declare @testdate datetime
set @testdate = getdate()-30
select @testdate
select CONVERT(datetime,ltrim(year(@testdate)-4) + '1001')
returns 2007-10-01 00:00:00.000
I would expect the date
2011-09-11 14:01:37.963
minus 4 years
2007-09-11 14:01:37.963
then the previous 1st October is 2006