0

Currently I'm doing this in SQL:

    select emp_code,in_time,out_time,worked_time,WT,shift_work_time,
    case when enable_overtime = 1 and TIMEDIFF(WT,shift_work_time) > 0
then hour(TIMEDIFF(WT,(shift_work_time))) else 0 end as OT
FROM myTable;

I am getting wrong OT at line 8,because shift_work_time is in hours format,so i want to convert shift_worke_time which is in hours to hh:mm:ss how can i do this? Thank you in advance

I have also tried TIME_FORMAT(shift_worke_time, '%H:%i:%s') but when shift_worke_time is 10 output is 00:00:10 but it should be

10:00:00
user9862376
  • 29
  • 10
  • check here; https://stackoverflow.com/questions/8338031/mysql-setup-the-format-of-datetime-to-dd-mm-yyyy-hhmmss-when-creating-a-tab – Deepak Dholiyan Aug 08 '18 at 06:48

1 Answers1

0

use STR_TO_DATE(shift_worke_time,'%H')

 SELECT 
  select emp_code,in_time,out_time,worked_time,WT,(shift_worke_time,'%H') as shift_worke_time,
    case when enable_overtime = 1 and TIMEDIFF(WT,(shift_worke_time,'%H')) > 0
then hour(TIMEDIFF(WT,(shift_worke_time,'%H'))) else 0 end as OT
FROM myTable;
Zaynul Abadin Tuhin
  • 31,407
  • 5
  • 33
  • 63