If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Delete DB entry after a given date (php/mysql) help

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-18-09, 10:09
danny_brazil danny_brazil is offline
Registered User
 
Join Date: Jul 2009
Posts: 19
Delete DB entry after a given date (php/mysql) help

Hello
Im looking for help with this chalenge:
I have a database with "future events" in it.

each even is given a DATE(example: Aug' 25 - film festival)

and a user will see all of the future event ONLY

WHAT i need here id a code the i can run every day (i can run it no problems) and it will DELETE old entries from the DB.

lets say today is Aug' 12 so i want to delete ALL entries with a date OF Aug 11 and back

Any help ?

Danny
Reply With Quote
  #2 (permalink)  
Old 08-18-09, 10:24
gvee gvee is offline
www.gvee.co.uk
 
Join Date: Jan 2007
Location: UK
Posts: 10,156
Are you certain you want to delete?

why not only show future dated entries by limiting your SELECT statement with an appropriate WHERE clause:
Code:
SELECT list
     , of
     , fields
FROM   events
WHERE  event_date > current_timestamp
__________________
George
Twitter | Blog
Reply With Quote
  #3 (permalink)  
Old 08-18-09, 10:26
danny_brazil danny_brazil is offline
Registered User
 
Join Date: Jul 2009
Posts: 19
even better

Man , thanks a lot.

One question though , what would be the best "timestamp" to use here ?

can you give me an example ?

thanks a lot !
Reply With Quote
  #4 (permalink)  
Old 08-18-09, 10:44
gvee gvee is offline
www.gvee.co.uk
 
Join Date: Jan 2007
Location: UK
Posts: 10,156
field should be datetime datatype and then you can use the current_timestamp() function to return the datetime of now

illustration:
Code:
SELECT current_timestamp()
__________________
George
Twitter | Blog
Reply With Quote
  #5 (permalink)  
Old 08-18-09, 15:37
danny_brazil danny_brazil is offline
Registered User
 
Join Date: Jul 2009
Posts: 19
working...thanks

Another question

lets say i have 20 entries from today on

i want to present JUST the 4 that are the closest to today ?

today is 18/08/2009

i have entries from sep 1 on...( 1..2..3..4..6..8..15...23....29)

but there ARE not order as i wrote here they are mixed

is there any way to SQL by distance from current date ?(lets say 1 week in advanced)

thanks
Reply With Quote
  #6 (permalink)  
Old 08-18-09, 17:08
gvee gvee is offline
www.gvee.co.uk
 
Join Date: Jan 2007
Location: UK
Posts: 10,156
Code:
SELECT TOP 4
       list
     , of
     , fields
FROM   events
WHERE  event_date > current_timestamp
ORDER
    BY event_date ASC
__________________
George
Twitter | Blog
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On