Click to See Complete Forum and Search --> : SQL Date


Grecian
09-10-2006, 04:14 AM
Hello,

I have a table that has a field which contains dates in the past. I want a sql statement which will select records that have the same date as today but in the past, rather like a "On this day..." request. My dates are stored in the format 31/01/2006.

Anybody any ideas?

russell_g_1
09-10-2006, 03:12 PM
what kind of database is it? and are your dates really stored as strings or is that just a management tool showing you a format?

Grecian
09-10-2006, 03:16 PM
it's an access2003 database and i'm using Frontpage as well.

My date values are stored in a field called Date in the format dd/mm/yyyy

CCCP
09-13-2006, 09:25 PM
Hello,

I have a table that has a field which contains dates in the past. I want a sql statement which will select records that have the same date as today but in the past, rather like a "On this day..." request. My dates are stored in the format 31/01/2006.

Anybody any ideas?
not the best query in terms of runtime optimization, but will give you an idea and a solution.
assuming your date column is called "my_date":

SELECT *
FROM ...
WHERE convert (char(2), datepart (mm, my_date)) + '-' + convert (char(2), datepart (dd, my_date)) =
convert (char(2), datepart (mm, getdate())) + '-' + convert (char(2), datepart (dd, getdate()))

For example, May 16 of each year will be represented as " 5-16"