Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Senior Coder
    Join Date
    Jun 2008
    Location
    Cornwall
    Posts
    2,098
    Thanks
    297
    Thanked 12 Times in 12 Posts

    deleting rows depending on date.

    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
    PHP Code:
    DELETE from codes WHERE expiredate today() 
    would that work?
    cheers

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,861
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    Code:
    DELETE from codes WHERE expiredate > date(now())
    (You may need to adjust the comparison operator, depending upon your requirement)
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    Senior Coder
    Join Date
    Jun 2008
    Location
    Cornwall
    Posts
    2,098
    Thanks
    297
    Thanked 12 Times in 12 Posts
    thanks mate

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,027
    Thanks
    79
    Thanked 4,436 Times in 4,401 Posts
    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
    Code:
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •