all groups > sql server mseq > august 2004 >
You're in the

sql server mseq

group:

Date calculation



Date calculation Bob
8/3/2004 10:37:13 AM
sql server mseq: Im relatively new with sql and im having a problem
creating a criteria based on todays date less 150 days.

I tried to use the following...
< GetDate () -150 however it will not let me use this.

I know that there must be away to do this, but I need
Re: Date calculation Hugo Kornelis
8/3/2004 9:59:59 PM
[quoted text, click to view]

Hi Bob,

Try it with DATEADD(day, -150, getdate()).

If you remove the space between getdate and (), your code would work as
well, but I recommend using DATEADD anyway - just subtracting 150 relies
on the internal storage of datetime values; this is not guaranteed to
remain unchanged between SQL Server versions.

Also remember that getdate() gives current date *AND* time. Not a problem
for "smaller than" comparissons, but if you ever have to match on "equal"
date, you'll have to use some extra tricks to get rid of the time portion.

Best, Hugo
--

AddThis Social Bookmark Button