I have a database full of information, one of the field's is a datefield. Basically what I want to do is run a query which will bring up rows where the date in that field is 30days or more older then the current date. I have quite a lot of things and my experience in PHP is good, I would be very grateful is somebody could shed some light on this.
If datefield is the time in milliseconds. Simply get today's date in milliseconds, then take off (1000 * 60 * 60 * 24 * [days]). Then do a SQL search for anything lower or equal to that time.
Thats easy. Just do a sql query that will subtract the unix date and the date under the datetime fields in the database. Make use of the predefined functions of the sql so no coding will undergo the server-scripts. Post if you get the query, or i'll post it though.
SELECT * FROM links WHERE `lchecked` < DATE_ADD(CURRENT_DATE,INTERVAL 30 DAY) Code (markup): //with $today being today's date SELECT TO_DAYS($today) - TO_DATE(NOW()) AS interval from links Code (markup): SELECT TO_DAYS(one_date) - TO_DAYS(another_date) FROM your_table Code (markup): So far I have tried these queries and tried to play around with them but could not get any of them to work. If you know the query I should be using then please show me I would be very grateful.
try this one, SELECT DATE_ADD('2009-01-01', INTERVAL 6/4 HOUR_MINUTE); -> '2009-01-04 12:20:00' SELECT DATE_SUB('2005-01-01 00:00:00', INTERVAL '1 1:1:1' DAY_SECOND); -> '2004-12-30 22:58:59' if you cant still get it, use the operator functions add, subtract, etc.. im really sleepy right now.. ^^
Sorry couldn't get your query to work but one of my colleagues found the answer: SELECT * FROM links WHERE (TO_DAYS(NOW()) - TO_DAYS(datefield))>30 Code (markup): Thanks anyway