Show records with dates 30 days old

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I need to know how to build an expression or use a date/time function in a
query to show records with a date that is more than 30 days old.
 
Hi

You can put the <(Date()-30)) in the criteria of the date field in
quetion or the following in SQL view replacing the tablename and
fieldname as appropriate WHERE (((TableName.DateField)<(Date()-30)))

Hope this helps
James
 
Thanks, James. It was just what I needed. I do have another question,
however. How do I limit the records displayed to the current year?
 
Thanks, James. It was just what I needed. I do have another question,
however. How do I limit the results to show just the current year's records?
 
Lewis said:
Thanks, James. It was just what I needed. I do have another question,
however. How do I limit the results to show just the current year's records?

The combination of over 30 days old and in the same calendar year will
always be false in January (well, except maybe the 31st) and of
questionable value in the first few months of any year.

Did you really mean to check the last 365 days? If so, you could modify
Lewis's solution to look like
Between (Date()-30)) And (Date()-365))

If you really wanted to do as you said,

Add to your WHERE clause:
AND YEAR(TableName.DateField) = YEAR(DATE)

The the query builder this might look like (in a new column):
Field: YEAR(TableName.DateField)
Show: no
Criteria: = YEAR(DATE)
 
Lewis said:
Thanks, James. It was just what I needed. I do have another question,
however. How do I limit the results to show just the current year's records?

The combination of over 30 days old and in the same calendar year will
always be false in January (well, except maybe the 31st) and of
questionable value in the first few months of any year.

Did you really mean to check the last 365 days? If so, you could modify
James's solution to look like
Between (Date()-30)) And (Date()-365))

If you really wanted to do as you said,

Add to your WHERE clause:
AND YEAR(TableName.DateField) = YEAR(DATE)

The the query builder this might look like (in a new column):
Field: YEAR(TableName.DateField)
Show: no
Criteria: = YEAR(DATE)





[message with incorrect attribution was canceled -- apologies to James
for any confusion]
 
Thanks for the solution. The 365 days tip is want I really needed.

Smartin said:
Lewis said:
Thanks, James. It was just what I needed. I do have another question,
however. How do I limit the results to show just the current year's records?

The combination of over 30 days old and in the same calendar year will
always be false in January (well, except maybe the 31st) and of
questionable value in the first few months of any year.

Did you really mean to check the last 365 days? If so, you could modify
James's solution to look like
Between (Date()-30)) And (Date()-365))

If you really wanted to do as you said,

Add to your WHERE clause:
AND YEAR(TableName.DateField) = YEAR(DATE)

The the query builder this might look like (in a new column):
Field: YEAR(TableName.DateField)
Show: no
Criteria: = YEAR(DATE)





[message with incorrect attribution was canceled -- apologies to James
for any confusion]
 
Back
Top