Jump to content

Query


sandy1028

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/72272-query/
Share on other sites

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 ???

Link to comment
https://forums.phpfreaks.com/topic/72272-query/#findComment-364461
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/72272-query/#findComment-364473
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.