Author Topic: Cara Menghitung Jam_In dan Jam_Out  (Read 140 times)

0 Members and 1 Guest are viewing this topic.

Offline Pujianto

  • Junior Member
  • *
  • Posts: 319
Cara Menghitung Jam_In dan Jam_Out
« on: August 28, 2019, 12:49:00 PM »
Dear Mastah..

Saya bikin Coding untuk menghitung jumlah jam kerja selama sehari.
Hasilnya kok kurang valid ya..
Ada yg bisa membisikin code yg benar gak ya?

Jam_In = 28/08/2019 07:50:29
Jam_Out = 28/08/2019 17:48:26

Hasilnya seharusnya = 09:57:57
Tapi pake coding dibawah hasilnya = 10:57:57

Ini Code Saya :
Code: [Select]
PADL(ALLTRIM(STR((Jam_out - Jam_in)/3600)),2,'00')+":"+ ;
PADL(ALLTRIM(STR(MOD(INT((Jam_out - Jam_in)/60),60))),2,'00')+":"+ ;
PADL(ALLTRIM(STR(MOD((Jam_out - Jam_in),60))),2,'00')

Offline Pujianto

  • Junior Member
  • *
  • Posts: 319
Re: Cara Menghitung Jam_In dan Jam_Out
« Reply #1 on: August 28, 2019, 03:18:24 PM »
Sudah Ketemu..
Special Thanks to Borislav Borissov

Code: [Select]
SET SECONDS ON

Time_In = DATETIME(2019, 8, 28, 07, 50, 29)
Time_Out = DATETIME(2019, 8, 28, 17, 48, 26)
? Sec2Time(Time_Out - Time_In)

SET SECONDS OFF

FUNCTION Sec2Time(nSecs)


    LOCAL c_hours, c_min, c_znak
    c_znak  = IIF(nSecs<0,[-],[])

    nSecs   = ABS(nSecs)

    c_hours = PADL(INT(nSecs/3600),10,[0])
    IF LEN(LTRIM(c_hours,1,[0])) > 3
       c_hours = LTRIM(c_hours,1,[0])
    ELSE
       c_hours = PADL(INT(nSecs/3600)     ,3,[0])
    ENDIF

    c_min   = PADL(INT((nSecs%3600)/60),2,[0])
    nSecs   = PADL(nSecs%60            ,2,[0])

RETURN c_znak+c_hours+":"+c_min + ":"+nSecs