Delete data more than 2 months old

  • Thread starter Thread starter AJCB
  • Start date Start date
A

AJCB

Hi there.

I have a field in a table which shows the date and time that a record was
created in Access.

I am wanting to run a query that will automatically delete data that is more
than 2 months old, but I cannot figure out what string to put in the query.

Can anyone help me?

Regards
AJ
 
DELETE FROM [YourTableNameHere]
WHERE [YourDateTimeFieldHere] < DateAdd("m", -2, Date());
 
Create a query with your table as its source. Create a column in the query
like this
HowOld: DateAdd("m",2,[Date Created])
In the criteria fior this column put
Check the query return the correct results and then change its type to a
delete query
 
Hi Dennis.

This did not work. I didn't get an error message, but all it put in the
field was the date and the time that the record was created.

Do you have any other ideas?

Dennis said:
Create a query with your table as its source. Create a column in the query
like this
HowOld: DateAdd("m",2,[Date Created])
In the criteria fior this column put
Check the query return the correct results and then change its type to a
delete query

AJCB said:
Hi there.

I have a field in a table which shows the date and time that a record was
created in Access.

I am wanting to run a query that will automatically delete data that is more
than 2 months old, but I cannot figure out what string to put in the query.

Can anyone help me?

Regards
AJ
 
It works OK but obviously I cannot see what you have done. Have you tried it
Allen's way instead ?

AJCB said:
Hi Dennis.

This did not work. I didn't get an error message, but all it put in the
field was the date and the time that the record was created.

Do you have any other ideas?

Dennis said:
Create a query with your table as its source. Create a column in the query
like this
HowOld: DateAdd("m",2,[Date Created])
In the criteria fior this column put
Check the query return the correct results and then change its type to a
delete query

AJCB said:
Hi there.

I have a field in a table which shows the date and time that a record was
created in Access.

I am wanting to run a query that will automatically delete data that is more
than 2 months old, but I cannot figure out what string to put in the query.

Can anyone help me?

Regards
AJ
 
I will try, but I am not really that confident using SQL queries, as I
usually cannot get them to work.

Dennis said:
It works OK but obviously I cannot see what you have done. Have you tried it
Allen's way instead ?

AJCB said:
Hi Dennis.

This did not work. I didn't get an error message, but all it put in the
field was the date and the time that the record was created.

Do you have any other ideas?

Dennis said:
Create a query with your table as its source. Create a column in the query
like this
HowOld: DateAdd("m",2,[Date Created])
In the criteria fior this column put
Now()
Check the query return the correct results and then change its type to a
delete query

:

Hi there.

I have a field in a table which shows the date and time that a record was
created in Access.

I am wanting to run a query that will automatically delete data that is more
than 2 months old, but I cannot figure out what string to put in the query.

Can anyone help me?

Regards
AJ
 
I am wanting to run a query that will automatically delete data that is more
than 2 months old,

Why?

You'll NEVER need to see historical data?

Bear in mind that deleting data will NOT free up space in your database (until
you Compact), and if you have suitable indexes, won't much affect the speed of
your queries, unless you have hundreds of thousands of records.
but I cannot figure out what string to put in the query.

< DateAdd("m", 2, Date())

will delete all records older than two months ago today. BACK UP YOUR DATABASE
first.
 
Back
Top