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 5 of 5
  1. #1
    Regular Coder
    Join Date
    Jun 2009
    Posts
    351
    Thanks
    75
    Thanked 0 Times in 0 Posts

    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?

  • #2
    Regular Coder xconspirisist's Avatar
    Join Date
    Jun 2006
    Location
    Great Britain.
    Posts
    138
    Thanks
    1
    Thanked 6 Times in 6 Posts
    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.

  • Users who have thanked xconspirisist for this post:

    kevinkhan (03-30-2010)

  • #3
    Regular Coder
    Join Date
    Jun 2009
    Posts
    351
    Thanks
    75
    Thanked 0 Times in 0 Posts
    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??

  • #4
    Regular Coder xconspirisist's Avatar
    Join Date
    Jun 2006
    Location
    Great Britain.
    Posts
    138
    Thanks
    1
    Thanked 6 Times in 6 Posts
    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.

  • #5
    Regular Coder
    Join Date
    Jun 2009
    Posts
    351
    Thanks
    75
    Thanked 0 Times in 0 Posts
    ok cool

    thanks for your help


  •  

    Posting Permissions

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