Re: Date comparison Question
| From: | Mark J. Reed | Date: | Mon, 07 Apr 2008 16:29:12 +0000 |
| Subject: | Re: Date comparison Question | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-272663@lists.php.net to get a copy of this message | ||
On Mon, Apr 7, 2008 at 11:42 AM, <admin@buskirkgraphics.com> wrote:
>t the data is fed from the database, CaldTime is timestamp and since
it will not allow me to have 2 timestamps in
> the same table
?? What database are you using? It sounds like it has a specific
meaning of "timestamp" - probably "the last time this row was
modified" - and you want an arbitrary date column, which would
probably be a different column type. Not a string, though. An actual
date type. possible names are date, datetime, datestamp...
, and you I set the CallEnd varchar(12). Storing the data they seem
to be the same for output. I checked hexadecimal and binary to look
for obscurities.
>
>
> $sqldata['CaldTime'] = "2008-04-07 11:15:32";
> $sqldata['CallEnd'] = "2008-04-07 11:17:17";
>
> $time1 = strtotime("$sqldata[CaldTime]");
> $time2 = strtotime("$sqldata[CallEnd]");
> $interval = $time2 - $time1;
>
> echo $interval;
>
> +++++++++++++++++++++++++++++++++++++++++++++++++++++++
> Displays like 1.75:0
> I am looking for a more precise time like 1:45 instead.
> Am I looking at this all wrong for time difference?
strtotime returns an integer number of seconds. The difference
between $time1 and $time2 is 105. If you want minutes and seconds,
you have to do the math yourself.
$interval_min = floor($interval/60);
$interval_sec = $interval % 60;
echo "$interval_min:$interval_sec";
--
Mark J. Reed <markjreed@mail.com>