Hello all,
I need to delete records from a table in a MySQL database that are more than 700 days old.
There is a column with the time of the record's entry "pPostDate", & the dates are in RFC 2822 Format... the column's format is VARCHAR, not date or datetime.
The date record looks like this... Sun, 08 May 2011 14:21:50 +0000.
I have tried a bunch of crap ( MySQL, or databases of any kind are not my strongest point)
Here are a few queries I have tried: -
SELECT * FROM cu_info.pi_search WHERE pPostDate BETWEEN DATE_FORMAT(NOW(),'%a, %m %b %Y %T %z') AND DATE_SUB(DATE_FORMAT(NOW(),'%a, %m %b %Y %T %z'), INTERVAL 700 DAY);
-
-
SELECT * FROM cu_info.pi_search WHERE DATE_SUB(pPostDate, INTERVAL 700 DAY);
-
-
SELECT * FROM cu_info.pi_search WHERE DATE_SUB(DATE_FORMAT(pPostDate,'%a, %m %b %Y %T %z'), INTERVAL 700 DAY);
-
I know that the queries do not include delete statements... I do not want to mess with that function until I am able to successfully access/return the records to delete.
Any help is greatly appreciated.
5 3009
DATE_FORMAT is used to convert a datetime to a string. Not the other way around. You need to use CONVERT for that. - SELECT stringDate
-
FROM someTable
-
WHERE CONVERT(stringDate, DATETIME) BETWEEN DATE_SUB(NOW(), INTERVAL DAYS 700) AND NOW()
You may or may not have to strip off the time zone stuff first.
Hey Rabbit, Thanks for your reply.
Your solution looks correct, except that the DateTime format in my case is RFC 2822... eg: Sun, 08 May 2011 14:21:50 +0000, not "2011-06-04 07:9:22"
I've tried converting it on the fly, but I'm not very savy in MySQL, so not very knowledgeable of it's built in functions.
You see, the problem is, the database has over 40 million entries already, but the table that I am using this delete feature on has 6 million, & it's already tied into software, & websites in circulation. So I just can't change the dateTime column to date format, because the Hash of the table's entries will change, & throw off the functionality of everything that depends on it. I want to leave it as is, & maybe add a new column, & have that one be another date format that MySQL functions are used to.
I didn't realize that MySQL didn't understand dates in RFC 2822 when I originally began.
Thanks again for your solution, It works, just not for my case of RFC 2822 Date Format.
Try substringing out everything from character 6 onwards and dropping the timezone before the convert.
Thanks again Rabbit,
I tried your suggestion... -
SELECT pHASH FROM cu_info.wc_search WHERE CONVERT(pPostDate, DATETIME) BETWEEN DATE_SUB(NOW(), INTERVAL 700 DAY) AND NOW();
-
-
SELECT pHASH FROM cu_info.wc_search WHERE CONVERT(pPostDate, DATETIME) NOT BETWEEN DATE_SUB(NOW(), INTERVAL 700 DAY) AND NOW();
-
however, it wouldn't work no matter how I re-wrote it with those statements. It did return results, but only the ones I didn't want.
So I decided to drop trying to deal with the 2822 formatted datetime column, & added a new one pUnixTimeStamp, & updated it with the row's pPostDate 2822 formatted datetime record converted to Unix TimeStamp (outside of MySQL).
I used the DATE_SUB function you suggested... - DATE_SUB(NOW(), INTERVAL 700 DAY))
But it had to be converted to TimeStamp to be used against pUnixTimeStamp,
You said to use the CONVERT function, so I snooped around, & found another converting function... UNIX_TIMESTAMP()
I placed the above functions inside UNIX_TIMESTAMP(), & it worked.
Here is the final string I now use... - SELECT pHASH FROM cu_info.wc_search WHERE pUnixTimeStamp < UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 700 DAY));
ps: The substring removal method was the way to go with the 2822 format datetime, but I didn't know how to do it in MySQL.
So it sounds like you got it figured out?
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Bruce A. Julseth |
last post by:
My MySQL.user table (user, host, password) looks like the following:
+---------+-----------+---------------------+
| user | host | password |...
|
by: Matt Liverance |
last post by:
I REALLY dont want to switch to oracle :( but I cant get these tables
working any faster.
I've got 2 dedicated servers, each with a slave, all run 32gig 15k rpm
raid 5 on u320 perc raid...
|
by: ms |
last post by:
Access 2000:
I am trying to delete duplicate records imported to a staging table leaving one
of the duplicates to be imported into the live table. A unique record is based
on a composite key of 3...
|
by: jkw |
last post by:
Hi - I created a linked table via ODBC to a SQL Server database. The
table in SQL Server contained over 12,000,000 records. Later, I
started a "Delete" query. When I realized that I was deleting...
|
by: ebru |
last post by:
about insert/delete/update records in mysql server with asp code
how can I insert record in mysql database.. I insert into database but if I leave one text box empty, its give me error how can...
|
by: pezholio |
last post by:
Hi,
I'm trying to put together a page that deletes records from a database based on if an item is unticked, I've got the existing items in an array (let's call it array1 for the sake of argument):...
|
by: kcdoell |
last post by:
Hello:
I am trying to write a code that will delete all records found in my DAO recordset Below is the code I have so far:
'Procdure to give the user the ability to delete all records
'for a...
|
by: Dilip1983 |
last post by:
Hi All,
I want to delete duplicate records from a large table.
There is one index(INDEX_U1) on 4 columns(col1,col2,col3,col4) which is in unusable state.
First of all when i tried to rebuild...
|
by: WyvsEyeView |
last post by:
Upon clicking Delete to delete the current record on frmTopics, I want several things to happen:
1) Display a custom message rather than Access's standard "You are about to delete n records" one....
|
by: ellenr |
last post by:
I have a 600 record mysql db. It has a timestamp field, auto incr id field, several varchar fields and several smallint fields. The id field is set as primary key. The access03 has a form...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |