Jump to content

Function/Query


hellouthere

Recommended Posts

This function and query should delete any records that are 30 minutes old...

 

function DateAdd($interval, $number, $date) {

    $date_time_array = getdate($date);
    $hours = $date_time_array['hours'];
    $minutes = $date_time_array['minutes'];
    $seconds = $date_time_array['seconds'];
    $month = $date_time_array['mon'];
    $day = $date_time_array['mday'];
    $year = $date_time_array['year'];

    switch ($interval) {
    
        case 'y':
        case 'yyyy':
            $year+=$number;
            break;
        case 'q':
            $year+=($number*3);
            break;
        case 'm':
            $month+=$number;
            break;
        case 'd':
        case 'w':
            $day+=$number;
            break;
        case 'ww':
            $day+=($number*7);
            break;
        case 'h':
            $hours+=$number;
            break;
        case 'n':
            $minutes+=$number;
            break;
        case 's':
            $seconds+=$number; 
            break;            
    }
    
    $timestamp= mktime($hours,$minutes,$seconds,$month,$day,$year);
    return $timestamp;
}

    $query = "DELETE FROM positions WHERE last_update <= ".date("Y-m-d H:i:s", DateAdd("n", -30, time()));

 

i honestly didnt write all of it but helped...

 

the script returns the error...

 

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '13:50:43' at line 1

Link to comment
https://forums.phpfreaks.com/topic/45268-functionquery/
Share on other sites

Query...

 

$query = "DELETE FROM positions WHERE last_update <= '".date("Y-m-d H:i:s", DateAdd("n", -30, time())."'");

 

Output...

 

DELETE FROM positions WHERE last_update <= '2007-04-02 15:26:24

 

Error...

 

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''2007-04-02 15:27:47' at line 1

Link to comment
https://forums.phpfreaks.com/topic/45268-functionquery/#findComment-219838
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.