Ronald Ramos wrote:

How can I use PHP to compute the difference between two dates(with
time)?
Let's say in mysql, I have field 1, login, and on field 2, I have
logout.

How can I compute the diffrence between login and logut and output it on
field 3 let's say totaltime.

Is this a mysql question? Or can PHP actually do this?

TIA

Both can do it, but it depends heavily on what type of date format it is. If it's a normal mysql date or datetime (not a timestamp) then you can grab it, then do:


$seconds = strtotime($field1) - strtotime($field2);

strtotime() does a good job of converting just about every type of formatted date.

If you're using a timestamp, there aren't any deliminators. I'm not sure if strtotime() will parse those as you want. In this case (and the other, actually) you can easily use SQL.

SELECT UNIX_TIMESTAMP(field1) - UNIX_TIMESTAMP(field2) AS secondsBetween FROM table

--
paperCrane <Justin Patrin>

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



Reply via email to