sandy1028 Posted October 8, 2007 Share Posted October 8, 2007 Hi, These are the fields in the table. timestamp state | varchar(1) | YES | | NULL | cputime | varchar(12) | YES | | NULL | memused | decimal(10,2) | YES | | NULL The values in fieldname state changes from R to C when the task is completed. Please help me with a query how can we find the timetaken to change the state from R to C. Quote Link to comment Share on other sites More sharing options...
~n[EO]n~ Posted October 8, 2007 Share Posted October 8, 2007 UPDATE timestamp SET state='C' WHERE id=1; Quote Link to comment Share on other sites More sharing options...
sandy1028 Posted October 8, 2007 Author Share Posted October 8, 2007 The change of state from R to C is dynamic when the particular task is completed. How can we find the time taken when the state changed to C. When state changes is there any query to find the particular timestamp. Quote Link to comment Share on other sites More sharing options...
~n[EO]n~ Posted October 8, 2007 Share Posted October 8, 2007 I didn't understand what are you trying to do. How can we find the time taken when the state changed to C. How is the state going to change, with any events or what ? Quote Link to comment Share on other sites More sharing options...
sandy1028 Posted October 8, 2007 Author Share Posted October 8, 2007 When the task or job is completed the state is changed to C from R, ie from running to completed state. Can we find the time between R to C Quote Link to comment Share on other sites More sharing options...
~n[EO]n~ Posted October 8, 2007 Share Posted October 8, 2007 Yes you can, store the time in a variable when the task has started and completed <?php $timestart=date("H:i"); // get the time /// do your task here $timecomplete=date("H:i"); /// after that deduct the time difference and save it $timetaken = $timecomplete - $timestart; ?> But how will the task occur, by pressing some buttons or what ??? Quote Link to comment Share on other sites More sharing options...
mezise Posted October 8, 2007 Share Posted October 8, 2007 Hi, the simplest way to do exactly what you've described is adding to your INSERTS/UPDATES information of start times when a record enters appropriate state, e.g. datetimeOfRState and datetimeOfCState. Then to obtain the taken time you just need to select a difference of these times. Times when a record enters given state may also be maintained using TRIGGERS. If your description is incomplete you must notice that this way is only for one change from state R to C. When you are not sure if requirements will change safer way is to create special table that will store information of changing states. Michal 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.