Posted by Jasper Bryant-Greene on 06/27/05 07:47
John Taylor-Johnston wrote:
> I could just change the field type. But how do you calculate it? I don't
> see much to inspire a start. I'm not a full-time coder either. More of a
> tinkerer. I don't want someone to do it for me, but need to get my head
> around how to do it.
> http://ca3.php.net/manual/en/function.strtotime.php
If you stick with a string data type, then I'd use the following to
convert it to a UNIX timestamp (seconds since 1970-01-01) and find the
number of days since 23 August 2003:
$unix_timestamp = strtotime($mydata->StampDate);
$timestamp_2003 = strtotime('2003-08-23');
$days_since_2003 = ($unix_timestamp - $timestamp_2003) / 60 / 60 / 24;
$days_since_2003 now contains the number of days since 2003 for that
date. You'd have to aggregate all your records to get the average hits
per day.
As I said, though, you should be using a MySQL date field. Have a look
at the MySQL manual for the corresponding functions to the above --
there's probably a quicker way with MySQL too.
Jasper
[Back to original message]
|