[thelist] SQL to select dates before x days

Paul Cowan evolt at funkwit.com
Wed May 15 20:29:01 CDT 2002


John Corry wrote:
> I am trying to write a query that will select all of the 'events' that
> are within 45 days in the future of right now from my 'events' table.

I don't know what DB you're using, but it sounds like it might be a
date-formatting thing. I'm an ASP and SQL Server guy myself, so this might
not be helpful, but you can do it DB-side in SQL Server with something like:

SELECT * FROM events WHERE eventDateTime <= DATEADD(day, 45, GetDate())

or, indeed,

SELECT * FROM events WHERE DATEDIFF(day, eventDateTime, GetDate()) <= 45

(or maybe swap "eventDateTime" and "GetDate()" in that last one... I can
never remember that).


> I got the syntax for this query out of my movie schedule database...it
> worked there, but it isn't working here....what am I doing wrong?

What error/incorrect data are you getting?


Paul





More information about the thelist mailing list