...

View Full Version : How to delete multiple records from a database with a certain date?



kevinkhan
03-30-2010, 02:21 PM
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?

xconspirisist
03-30-2010, 02:25 PM
You could use wildcards within your query (LIKE '2010-03-30%'), but a nicer way of doing it would be this:


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.

kevinkhan
03-30-2010, 02:30 PM
You could use wildcards within your query (LIKE '2010-03-30%'), but a nicer way of doing it would be this:


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??

xconspirisist
03-30-2010, 02:36 PM
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.

kevinkhan
03-30-2010, 02:42 PM
ok cool

thanks for your help ;)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum