Page 1 of 1
SQL - Delete A Selected Month
Posted: Sun 25 Apr 2021 11:18 am
by Mapantz
I've ran across an issue with some of my data in my 'Monthly' table in MySQL
I think I have found the issue, but I need to delete a specific month/year in PHPMyAdmin. Does anyone know an SQL query I can run to do that?
I don't fancy trying to do it manually..
Re: SQL - Delete A Selected Month
Posted: Sun 25 Apr 2021 11:46 am
by freddie
Code: Select all
DELETE FROM Monthly WHERE LogDateTime > STR_TO_DATE('2021,2,28 23,59,59', '%Y,%m,%d %h,%i,%s') AND LogDateTime < STR_TO_DATE('2021,4,1 0,0,0', '%Y,%m,%d %h,%i,%s');
To delete March 2021.
I would test it first, though.
Re: SQL - Delete A Selected Month
Posted: Sun 25 Apr 2021 12:11 pm
by Mapantz
Thanks freddy
I did manage to work it out in the end, with:
Code: Select all
DELETE
FROM Monthly
WHERE LogDateTime >= '2020-12-01 00:00' AND LogDateTime <= '2020-12-31 23:50'
I used
SELECT * before
DELETE first, just to check it wouldn't do the wronbg thing.
Re: SQL - Delete A Selected Month
Posted: Sun 25 Apr 2021 1:13 pm
by freddie
That's good, well done. I've learned something too - I didn't know you could use
in your WHERE clause - I thought you needed to use the function STR_TO_DATE to turn the date string into a datetime database object.