Re: mysql timestamp - subtracting two times
| From: | Michael Teter | Date: | Mon, 03 Jul 2000 15:13:35 +0000 |
| Subject: | Re: mysql timestamp - subtracting two times | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-4509@lists.php.net to get a copy of this message | ||
I don't know much PHP or MySQL yet, but maybe this
will help you.
I would let the database server do the math for me.
something like this:
$strQuery = "select theName, theTime, theTime -
'$oldTime' as theTimeSpan from myTable"
I think you can probably do date math. I just don't
remember what the exact mechanism would be. could be
simple +/-, or perhaps it's a function like
DateAdd(time2, -time1).
--- Nick Riemondi <nick@outerscape.net> wrote:
> Hey,
> I'm trying to find a useful way to get the amount of
> time that passed
> between two mysql timestamps (hrs:mins). Anyone
> have any ideas?
> Obviously you can't just subtract them. Here is
> some code I'm using to
> display the timestamp in a nice fashion. Basically
> I'm needing to
> replace the "$time = $timestamp - $lastone;" with
> something useful.
>
> Thanks!
> Nick Riemondi
>
>
> ---------------------------------------
>
> function mysql_to_epoch($datestr) {
>
>
ereg("([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})",$datestr,
> $regs);
> return date("D, j M Y, h:i:s
> a",mktime($regs[4],$regs[5], $regs[6],
> $regs[2],$regs[3], $regs[1]));
> }
>
> #####################
>
> $result = my_query("select name,time_ from time");
> while (list($name,$timestamp) =
> mysql_fetch_row($result)) {
>
> print mysql_to_epoch($timestamp);
>
> $time = $timestamp - $lastone;
>
> print "
> <br>
> $timestamp<br>
> $time<br>
> <br><br>
> ";
>
> $lastone = $timestamp;
>
> };
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail:
> php-general-unsubscribe@lists.php.net
> For additional commands, e-mail:
> php-general-help@lists.php.net
> To contact the list administrators, e-mail:
> php-list-admin@lists.php.net
>
__________________________________________________
Do You Yahoo!?
Kick off your party with Yahoo! Invites.
http://invites.yahoo.com/