Re: [PHP] Re: I think this is a mysql question

2004-02-12 Thread Marek Kilimajer
Ronald Ramos wrote:

create table oras(
NameVARCHAR(30),
TimeIn DATETIME,
TimeOut DATETIME,
Total   DATETIME
);
insert into oras values('Nhadie','2004-10-10 10:10:00','2004-11-11
12:12:00','TIMEDIFF(TimeIn,TImeOut)');
Hi,

Are those correct? Because the value on the Total field is 000-00-00
00:00:00.
I think there's something wrong. I'm using 4.0.
mysql select * from oras;
++-+-+--
---+
| Name   | TimeIn  | TimeOut | Total
|
++-+-+--
---+
| Nhadie | 2004-10-10 10:10:00 | 2004-11-11 12:12:00 | -00-00
00:00:00 |
++-+-+--
---+
1 row in set (0.01 sec)
TIA
I would not use DATETIME column type for Total as it is dependable on 
the number of days in the month. Use INT and store the number of seconds 
instead. Then you can update the column using:

UPDATE oras SET Total = SELECT UNIX_TIMESTAMP(field1) - 
UNIX_TIMESTAMP(field2) [WHERE where_condition]

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


Re: [PHP] Re: I think this is a mysql question

2004-02-12 Thread Marek Kilimajer
Ronald Ramos wrote:

create table oras(
NameVARCHAR(30),
TimeIn DATETIME,
TimeOut DATETIME,
Total   DATETIME
);
insert into oras values('Nhadie','2004-10-10 10:10:00','2004-11-11
12:12:00','TIMEDIFF(TimeIn,TImeOut)');
Hi,

Are those correct? Because the value on the Total field is 000-00-00
00:00:00.
I think there's something wrong. I'm using 4.0.
mysql select * from oras;
++-+-+--
---+
| Name   | TimeIn  | TimeOut | Total
|
++-+-+--
---+
| Nhadie | 2004-10-10 10:10:00 | 2004-11-11 12:12:00 | -00-00
00:00:00 |
++-+-+--
---+
1 row in set (0.01 sec)
TIA
I would not use DATETIME column type for Total as it is dependable on 
the number of days in the month. Use INT and store the number of seconds 
instead. Then you can update the column using:

UPDATE oras SET Total = SELECT UNIX_TIMESTAMP(TimeIn) - 
UNIX_TIMESTAMP(TimeOut) [WHERE where_condition]

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


RE: [PHP] Re: I think this is a mysql question

2004-02-11 Thread Ronald Ramos
create table oras(
NameVARCHAR(30),
TimeIn DATETIME,
TimeOut DATETIME,
Total   DATETIME
);

insert into oras values('Nhadie','2004-10-10 10:10:00','2004-11-11
12:12:00','TIMEDIFF(TimeIn,TImeOut)');

Hi,

Are those correct? Because the value on the Total field is 000-00-00
00:00:00.
I think there's something wrong. I'm using 4.0.


mysql select * from oras;
++-+-+--
---+
| Name   | TimeIn  | TimeOut | Total
|
++-+-+--
---+
| Nhadie | 2004-10-10 10:10:00 | 2004-11-11 12:12:00 | -00-00
00:00:00 |
++-+-+--
---+
1 row in set (0.01 sec)

TIA












-Original Message-
From: Justin Patrin [mailto:[EMAIL PROTECTED] 
Sent: Thursday, February 12, 2004 9:08 AM
To: [EMAIL PROTECTED]
Subject: [PHP] Re: I think this is a mysql question


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

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