RE: [PHP] php + mysql - timstamp - calculate hours remaining
| From: | Albert | Date: | Tue, 10 Jan 2006 13:39:03 +0000 |
| Subject: | RE: [PHP] php + mysql - timstamp - calculate hours remaining | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-228400@lists.php.net to get a copy of this message | ||
Gregory Machin wrote:
> I have a table with a timestamp column and would like to use his to
> calculate the age of the record . how would i go about this...
Convert your timestamp to a unix timestamp (see mktime() function).
Use the value returned by time() to calculate the difference in seconds.
$age = time() - $tableTimestamp;
Divide by 3600 to get hours
> I would also like to exicute a mysql stament that pasess the tables and
> removes fields older than say 72 hours. how would i go about this . ?
Get a timestamp of 72 hours ago:
$olderThan72Hours = time() - (72 * 3600);
Convert to the same format as your timestamp column:
$timestamp = date('Y-m-d H:i:s', $olderThan72Hours);
Delete the records from the table:
mysql_query("DELETE FROM table WHERE timestamp >= '$timestamp'") or
die('Could not delete from table');
HTH
Albert
--
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.1.371 / Virus Database: 267.14.16/225 - Release Date: 2006/01/09