...

View Full Version : deleting rows depending on date.



LJackson
03-02-2009, 11:11 AM
Hi All,

i want my website to check all the records in my codes table and delete the records where the expiredate is less than "todays" date, so there is never any old data displayed.

would it be something like this

DELETE * from codes WHERE expiredate > today()

would that work?
cheers

abduraooft
03-02-2009, 11:43 AM
DELETE from codes WHERE expiredate > date(now())
(You may need to adjust the comparison operator, depending upon your requirement)

LJackson
03-02-2009, 11:57 AM
thanks mate :)

Old Pedant
03-02-2009, 08:06 PM
Isn't that *BACKWARDS*????

You will be deleting records where the expireDate is *AFTER* NOW().

That is, you will be deleting records where the expireDate is tomorrow...and next week...and next year.

If you want to zap records where the expireDate is *ALREADY PAST*, it should be


DELETE from codes WHERE expiredate < now()

Note that I did *NOT* use date(now()) (which, incidentally, is the same as currentDate() so why not use the simpler form?). If you use now() alone, then you will also be deleting records that expired today but EARLIER IN THE DAY than the current moment. If you don't have times in expiredate then it won't make any difference, of course.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum