newphpcoder Posted March 20, 2012 Share Posted March 20, 2012 Hi.. I have datetime data in my table kanban_data field chemicalweighing_dateEntry. sample data of chemicalweighing_dateEntry: 2012-03-20 08:12:55 2012-03-20 08:16:44 2012-03-20 08:19:28 2012-03-20 08:20:17 2012-03-20 08:27:52 2012-03-20 08:28:36 2012-03-20 08:29:03 2012-03-20 08:31:47 2012-03-20 08:32:24 2012-03-20 08:35:45 I need to get the aging of chemicalweighing_dateEntry. using this formula: Aging time (00:00:00) = now() - SUM of chemicalweighing_dateEntry. I don't know what mysql function should I used to get the aging time. Thank you Quote Link to comment Share on other sites More sharing options...
fenway Posted March 25, 2012 Share Posted March 25, 2012 SUM() of datetimes doesn't make any sense. Quote Link to comment Share on other sites More sharing options...
newphpcoder Posted March 25, 2012 Author Share Posted March 25, 2012 First, I get the elapse time using this code: TIMEDIFF(compounding_DATE_ENTRY,chemicalweighing_DATE_ENTRY) AS elapse1, TIMEDIFF(extrusion_DATE_ENTRY,compounding_DATE_ENTRY) AS elapse2, TIMEDIFF(forming_DATE_ENTRY,extrusion_DATE_ENTRY) AS elapse3, TIMEDIFF(deflashing_DATE_ENTRY,forming_DATE_ENTRY) AS elapse4 then I use avg to get the aging per elapse. here is the code: age_count_wip_chemical_weighing = (SELECT SEC_TO_TIME(time_to_sec(NOW()) - AVG(TIME_TO_SEC(elapse1))) AS age_count_wip_chemical_weighing FROM kanban_data ORDER BY elapse1), age_count_wip_compounding = (SELECT SEC_TO_TIME(time_to_sec(NOW()) - AVG(TIME_TO_SEC(elapse2))) AS age_count_wip_compounding FROM kanban_data ORDER BY elapse2), age_count_wip_extrusion = (SELECT SEC_TO_TIME(time_to_sec(NOW()) - AVG(TIME_TO_SEC(elapse3))) AS age_count_wip_extrusion FROM kanban_data ORDER BY elapse3), age_count_wip_forming = (SELECT SEC_TO_TIME(time_to_sec(NOW()) - AVG(TIME_TO_SEC(elapse4))) AS age_count_wip_forming FROM kanban_data ORDER BY elapse4); Is it right my query to get the aging? Thank you so much Quote Link to comment Share on other sites More sharing options...
fenway Posted March 29, 2012 Share Posted March 29, 2012 All these subqueries make me think something is horribly wrong. Quote Link to comment 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.