Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-30-2010, 01:21 PM   PM User | #1
kevinkhan
Regular Coder

 
Join Date: Jun 2009
Posts: 350
Thanks: 75
Thanked 0 Times in 0 Posts
kevinkhan is an unknown quantity at this point
How to delete multiple records from a database with a certain date?

I have a database with a table called phone_number_sent and a column with a title of date_sent..

How do i delete all records with a date of 2010-03-30??

the date_sent column is formatted like the following numbers..
2010-03-30 11:16:30
2010-03-30 11:16:43

i tryed
DELETE FROM `phone_number_sent` WHERE `date_sent` LIKE `2010-03-30`
but didnt work

can anybody tell me what i can write?
kevinkhan is offline   Reply With Quote
Old 03-30-2010, 01:25 PM   PM User | #2
xconspirisist
Regular Coder

 
xconspirisist's Avatar
 
Join Date: Jun 2006
Location: Great Britain.
Posts: 137
Thanks: 1
Thanked 6 Times in 6 Posts
xconspirisist has a little shameless behaviour in the past
You could use wildcards within your query (LIKE '2010-03-30%'), but a nicer way of doing it would be this:

Code:
DELETE FROM `phone_number_sent` WHERE date_format(date_sent, '%Y-%m-%d') = "2010-03-30"
Please make a backup before running my suggestion - I do not have your database schema so I have not tested it.
__________________
If I have been helpful, use the "thank" button - It makes me happy!

xconspirisist.co.uk - homepage of my online alias
technowax.net - a community for people interested in all forms of modern technology.
xconspirisist is offline   Reply With Quote
Users who have thanked xconspirisist for this post:
kevinkhan (03-30-2010)
Old 03-30-2010, 01:30 PM   PM User | #3
kevinkhan
Regular Coder

 
Join Date: Jun 2009
Posts: 350
Thanks: 75
Thanked 0 Times in 0 Posts
kevinkhan is an unknown quantity at this point
Quote:
Originally Posted by xconspirisist View Post
You could use wildcards within your query (LIKE '2010-03-30%'), but a nicer way of doing it would be this:

Code:
DELETE FROM `phone_number_sent` WHERE date_format(date_sent, '%Y-%m-%d') = "2010-03-30"
Please make a backup before running my suggestion - I do not have your database schema so I have not tested it.
Yes this worked thanks

what is a wildcard??
kevinkhan is offline   Reply With Quote
Old 03-30-2010, 01:36 PM   PM User | #4
xconspirisist
Regular Coder

 
xconspirisist's Avatar
 
Join Date: Jun 2006
Location: Great Britain.
Posts: 137
Thanks: 1
Thanked 6 Times in 6 Posts
xconspirisist has a little shameless behaviour in the past
A wildcard is the % symbol, which "matches" almost any character when used in a search. In your example we specified the date and then used the wildcard to match the time part of your date field.
__________________
If I have been helpful, use the "thank" button - It makes me happy!

xconspirisist.co.uk - homepage of my online alias
technowax.net - a community for people interested in all forms of modern technology.
xconspirisist is offline   Reply With Quote
Old 03-30-2010, 01:42 PM   PM User | #5
kevinkhan
Regular Coder

 
Join Date: Jun 2009
Posts: 350
Thanks: 75
Thanked 0 Times in 0 Posts
kevinkhan is an unknown quantity at this point
ok cool

thanks for your help
kevinkhan is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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 On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:32 AM.


Advertisement
Log in to turn off these ads.