Re: I think this is a mysql question

From: Date: Thu, 12 Feb 2004 01:07:54 +0000
Subject: Re: I think this is a mysql question
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-177467@lists.php.net to get a copy of this message
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>

« previous php.general (#177467) next »