View Full Version : deleting rows depending on date.
03-02-2009, 10:11 AM
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?
03-02-2009, 10:43 AM
DELETE from codes WHERE expiredate > date(now())
(You may need to adjust the comparison operator, depending upon your requirement)
03-02-2009, 10:57 AM
thanks mate :)
03-02-2009, 07: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.
Powered by vBulletin® Version 4.2.2 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.