SQLTeam.com | Weblogs | Forums

Taking 3 days away


#1

Hi

I have a table called closed that has two fields

CLINO and SEL0002

in the SEL0002 field I have a date strings eg 2010-10-07 how do take 3 days away from all the dates in this field so that the example becomes 2010-10-04.

Thanks


#2

select CLINO,
SEL002 from closed
where SEL002=DATEADD(day,-3,SEL002)


#3

Hi

Thanks for replying this isn't working is it because the field SEL0002 is not a date field?.


#4
...
where SEL002=DATEADD(day,-3, CONVERT(Date, SEL0002))

SEL002 must be in "yyyymmdd" or "yyyy-mm-dd" format for this to work.

I would have expected SQl to do this IMplicitly, so something is probably wrong - e.g. some data is not a valid date. Post the exact error message pls.