datepart

  • Thread starter Thread starter Jean-Paul
  • Start date Start date
J

Jean-Paul

HI,
I want to delete all records older then one year from now.

What would be the best datepart-syntax or SQL command?

Thanks
 
hi Jean-Paul,

Jean-Paul said:
I want to delete all records older then one year from now.
What would be the best datepart-syntax or SQL command?
Try this:

DELETE FROM yourTable
WHERE yourDateField < CDate(Replace(Now(), Year(Now()), Year(Now())-1))



mfG
--> stefan <--
 
HI,
I want to delete all records older then one year from now.

What would be the best datepart-syntax or SQL command?

Thanks

Don't use DatePart at all. Instead use DateAdd:

DELETE * FROM tablename
WHERE [datefield] < DateAdd("yyyy", -1, Date());

Back up your database first of course! Deleted records cannot be recovered.
 
OK, but one question...

Will this delete all records from 2007 or only the ones realy 1 year old
from the current date (all those older then 13/10/07)

JP
HI,
I want to delete all records older then one year from now.

What would be the best datepart-syntax or SQL command?

Thanks

Don't use DatePart at all. Instead use DateAdd:

DELETE * FROM tablename
WHERE [datefield] < DateAdd("yyyy", -1, Date());

Back up your database first of course! Deleted records cannot be recovered.
 
OK, but one question...

Will this delete all records from 2007 or only the ones realy 1 year old
from the current date (all those older then 13/10/07)

The latter. That's how I interpreted "one year from today". If that's not what
you want please explain what you want.
 
Back
Top