Wiranata Posted January 16, 2013 Share Posted January 16, 2013 hi any body know about find different from 2 table. example table 1 start time 12:23:21 table 2 start time 01:12:12 can any body help me..please Quote Link to comment https://forums.phpfreaks.com/topic/273255-find-time-different-2-table-mysql/ Share on other sites More sharing options...
Barand Posted January 17, 2013 Share Posted January 17, 2013 Yes, I can confirm that the time in table Table1 is different from the time in Table2. Is there anything else? We'll need more information than that if there is. Quote Link to comment https://forums.phpfreaks.com/topic/273255-find-time-different-2-table-mysql/#findComment-1406257 Share on other sites More sharing options...
Wiranata Posted January 17, 2013 Author Share Posted January 17, 2013 Yes, I can confirm that the time in table Table1 is different from the time in Table2. Is there anything else? We'll need more information than that if there is. yeah... i want make form to find different time where time from 2 different table, i have table 1 start time 12:23:21 table 2 start time 01:12:12 then how can i show the difference in HH:MM:SS format? please help me..i tired about it...i can't sleep in 2 week because this problem any u need more information again about its? Quote Link to comment https://forums.phpfreaks.com/topic/273255-find-time-different-2-table-mysql/#findComment-1406408 Share on other sites More sharing options...
Barand Posted January 17, 2013 Share Posted January 17, 2013 This will find the difference between the two times. As there is no date, the same date is assumed. Hope this is what you meant CREATE TABLE table1 ( id INT NOT NULL PRIMARY KEY, starttime TIME ); CREATE TABLE table2 ( id INT NOT NULL PRIMARY KEY, starttime TIME ); INSERT INTO table1 VALUES (1, '12:23:21'); INSERT INTO table2 VALUES (1, '01:12:12'); SELECT t1.starttime as time1, t2.starttime as time2, SEC_TO_TIME(TIME_TO_SEC(t1.starttime) - TIME_TO_SEC(t2.starttime)) as diff FROM table1 t1 INNER JOIN table2 t2 USING (id); The result from the query was time1 | time2 | diff 12:23:21 | 01:12:12 | 11:11:09 Quote Link to comment https://forums.phpfreaks.com/topic/273255-find-time-different-2-table-mysql/#findComment-1406419 Share on other sites More sharing options...
Wiranata Posted January 17, 2013 Author Share Posted January 17, 2013 This will find the difference between the two times. As there is no date, the same date is assumed. Hope this is what you meant CREATE TABLE table1 ( id INT NOT NULL PRIMARY KEY, starttime TIME ); CREATE TABLE table2 ( id INT NOT NULL PRIMARY KEY, starttime TIME ); INSERT INTO table1 VALUES (1, '12:23:21'); INSERT INTO table2 VALUES (1, '01:12:12'); SELECT t1.starttime as time1, t2.starttime as time2, SEC_TO_TIME(TIME_TO_SEC(t1.starttime) - TIME_TO_SEC(t2.starttime)) as diff FROM table1 t1 INNER JOIN table2 t2 USING (id); The result from the query was time1 | time2 | diff 12:23:21 | 01:12:12 | 11:11:09 yeah....maybe i should reload my question. i have 2 form upload file with time. and 2 table to save time. 1 form upload to upload task and 1 form upload to upload answer task and i have 2 table upload file CREATE TABLE uploadyask( id INT NOT NULL PRIMARY KEY, timeupload TIMESTAMP ); CREATE TABLE task( id INT NOT NULL PRIMARY KEY, time TIMESTAMP ); i follow your code in my view archives but nothing happen Quote Link to comment https://forums.phpfreaks.com/topic/273255-find-time-different-2-table-mysql/#findComment-1406461 Share on other sites More sharing options...
Barand Posted January 17, 2013 Share Posted January 17, 2013 if you are using timestamps (which have a date as well as a time, by the way, unlike your data examples) then CREATE TABLE table1 ( id INT NOT NULL PRIMARY KEY, starttime TIMESTAMP ); CREATE TABLE table2 ( id INT NOT NULL PRIMARY KEY, starttime TIMESTAMP ); INSERT INTO table1 VALUES (1, '2012-01-17 12:23:21'); INSERT INTO table2 VALUES (1, '2012-01-17 01:12:12'); SELECT t1.starttime, t2.starttime, SEC_TO_TIME(UNIX_TIMESTAMP(t1.starttime) - UNIX_TIMESTAMP(t2.starttime)) as diff FROM table1 t1 INNER JOIN table2 t2 USING (id); Quote Link to comment https://forums.phpfreaks.com/topic/273255-find-time-different-2-table-mysql/#findComment-1406504 Share on other sites More sharing options...
Wiranata Posted January 17, 2013 Author Share Posted January 17, 2013 if you are using timestamps (which have a date as well as a time, by the way, unlike your data examples) then CREATE TABLE table1 ( id INT NOT NULL PRIMARY KEY, starttime TIMESTAMP ); CREATE TABLE table2 ( id INT NOT NULL PRIMARY KEY, starttime TIMESTAMP ); INSERT INTO table1 VALUES (1, '2012-01-17 12:23:21'); INSERT INTO table2 VALUES (1, '2012-01-17 01:12:12'); SELECT t1.starttime, t2.starttime, SEC_TO_TIME(UNIX_TIMESTAMP(t1.starttime) - UNIX_TIMESTAMP(t2.starttime)) as diff FROM table1 t1 INNER JOIN table2 t2 USING (id); thanks for replay..but i've try your code but when i run that code nothing happen your code is succesfully in mysql not my form to find different time Quote Link to comment https://forums.phpfreaks.com/topic/273255-find-time-different-2-table-mysql/#findComment-1406509 Share on other sites More sharing options...
Barand Posted January 17, 2013 Share Posted January 17, 2013 Sorry about that but my lack of psychic abilty prevents me from doing any more for you. Quote Link to comment https://forums.phpfreaks.com/topic/273255-find-time-different-2-table-mysql/#findComment-1406529 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.