Re: How to delete 3 months old records in my database?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello,

Try something like:

$oldDate = new DateTime();
$oldDate->sub(new DateInterval('P3M'));
$old_records_to_delete = $oldDate->format('Y-m-d');


Hope this helps,

Si

Sent from my iPhone

On 2 Aug 2013, at 11:58, Karl-Arne Gjersøyen <karlarneg@xxxxxxxxx> wrote:

> Hello again, folks!
> I wish to delete records in my database that is older than 3 months.
> 
> $todays_date = date('Y-m-d');
> $old_records_to_delete =  ???
> 
> if($old_records_to_delete){
> include(connect.php);
> $sql = "DELETE FROM table WHERE date >= '$old_records_to_delete'";
> mysql_query($sql, $connect_db) or die(mysql_error());
> }
> 
> Thank you very much for your help to understand also this question :)
> 
> Karl

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php






[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux