Code:
$sql = "SELECT * FROM task";
$res = $conn->query($sql);
$len = $res->num_rows;
if($len > 0){
while($row = $res->fetch_array(MYSQLI_ASSOC){
if($row['status'] == "Completed" && empty($row['tot_hours'])){
$sql = "UPDATE task SET tot_hours = TIME_TO_SEC(TIMEDIFF(date_end,date_start))/3600 WHERE status = 'Completed'";
}
else{
continue;
}
}
}
(Not familiar with PDO, but something like this in application/espo/core/utils/cron/job.php)
protected function updateHours(){
$pdo = $this->getEntityManager->getPDO();
$query = "SELECT * FROM task";
$sth = $pdo->prepare($query);
$sth->execute();
while($row = $sth->fetch(PDO::FETCH_ASSOC)){
if($row['status'] == "Completed" && empty($row['tot_hours'])){
$sec_query = "UPDATE task SET tot_hours = TIME_TO_SEC(TIMEDIFF(date_end,date_start)/3600 WHERE status = 'Completed' ";
$fst = prepare($sec_query)->execute();
else{
continue;
}
}
}
Not sure where to execute the code? Need assistance on how and where to execute the code above to calculate the difference of datetime. Maybe run it as a cron job.
$sql = "SELECT * FROM task";
$res = $conn->query($sql);
$len = $res->num_rows;
if($len > 0){
while($row = $res->fetch_array(MYSQLI_ASSOC){
if($row['status'] == "Completed" && empty($row['tot_hours'])){
$sql = "UPDATE task SET tot_hours = TIME_TO_SEC(TIMEDIFF(date_end,date_start))/3600 WHERE status = 'Completed'";
}
else{
continue;
}
}
}
(Not familiar with PDO, but something like this in application/espo/core/utils/cron/job.php)
protected function updateHours(){
$pdo = $this->getEntityManager->getPDO();
$query = "SELECT * FROM task";
$sth = $pdo->prepare($query);
$sth->execute();
while($row = $sth->fetch(PDO::FETCH_ASSOC)){
if($row['status'] == "Completed" && empty($row['tot_hours'])){
$sec_query = "UPDATE task SET tot_hours = TIME_TO_SEC(TIMEDIFF(date_end,date_start)/3600 WHERE status = 'Completed' ";
$fst = prepare($sec_query)->execute();
else{
continue;
}
}
}
Not sure where to execute the code? Need assistance on how and where to execute the code above to calculate the difference of datetime. Maybe run it as a cron job.