by Anonymous (267 Submissions)
Category: Databases/Data Access/DAO/ADO
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Sat 12th March 2005
Date Added: Mon 8th February 2021
Rating: (1 Votes)
time in, time out, punched in, puched out calculate time, time spent
You may declare the variables used in the procedures as private variables in the declaration section in your form.
' ==============================================================================
' To calculate time IN and OUT by employee...
' Example: VVIN = "12/02/2005 11:15:30 AM"
' VVOUT = "12/03/2005 10:05:30 PM"
' This routine (TIME_IN_AND_OUT) is the best among the three modules listed blw.
'
' This is a good code to calculate User Time Punched in and out during
' the day and in any given day. No time limit for this codes.
' ==============================================================================
Private Sub TIME_IN_AND_OUT(VVIN, VVOUT)
Dim Return_Minute
Dim Return_Hour
Dim valrtn
Date_And_Time_Punched_In = CDate(VVIN)
Date_And_Time_Punched_Out = CDate(VVOUT)
' Calculate number of days between punched in and now(date).
' ------------------------------------------------------------
Number_Days = DateDiff("d", chk_Time_In, chk_Date_And_Time_Out)
Number_Of_Hour_Worked = DateDiff("h", Date_And_Time_Punched_In, _
Date_And_Time_Punched_Out)
If Number_Of_Hour_Worked = 1 Then ' It is the same day...
Number_Of_Hour_Worked = 0
Else
Number_Of_Hour_Worked = Number_Of_Hour_Worked - 1
End If
' Calculate minute
Minutecalculated = DateDiff("n", VVIN, VVOUT)
' Return number of hours in minutes worked...
'--------------------------------------------
Return_Hour = str(Round((Minutecalculated \ 60), 2))
' Return number of minutes in total minutes worked...
'--------------------------------------------
Return_Minute = "." & str(Round((Minutecalculated Mod 60), 2))
' Calculate total hour and minutes worked
' ============================================
valrtn = Format(Return_Minute, "##0.00")
TotalHourWorked = Return_Hour + Val(valrtn)
If Len(Trim(Return_Hour)) <> 0 Then
Me.Hours_In_Word.Caption = Return_Hour & " Hour(s) " & " and " & Return_Minute & " Minute(s) "
ElseIf Val(Return_Hour) = 0 And Val(valrtn) <> 0 Then
Me.Hours_In_Word.Caption = Return_Minute & " Minute(s) "
Else
Me.Hours_In_Word.Caption = "0" & " Hour(s) " & " and " & "0" & " Minute(s) "
End If
' Calculate overtime hour worked
' ============================================
If Val(TotalHourWorked) > 8 Then
Overtime_Hour_Worked = (TotalHourWorked - 8)
Else
RegularHour = TotalHourWorked
End If
' Calculate regular hour worked
' ============================================
If Not IsEmpty(Overtime_Hour_Worked) Or IsNull(Overtime_Hour_Worked) Then
RegularHour = str((TotalHourWorked - Overtime_Hour_Worked))
End If
End Sub
================================================================================
' To calculate number of day between time IN and OUT...
' Example: xChkedTimeIn = "12/02/2005 11:15:30 AM"
' xChkedDateAndTimeNow="12/03/2005 10:05:30 PM"
================================================================================
Function xNumber_of_Days(xChkedTimeIn, xChkedDateAndTimeNow) 'Date_And_Time_Punched_In, Date_And_Time_Punched_In)
Dim In_Minute As Double
chk_Time_In = CDate(xChkedTimeIn)
chk_Date_And_Time_Out = CDate(xChkedDateAndTimeNow)
Number_hours = DateDiff("h", chk_Time_In, chk_Date_And_Time_Out)
' Calculate number of days between punched in and now(date).
' ------------------------------------------------------------
Number_Days = DateDiff("d", chk_Time_In, chk_Date_And_Time_Out)
If Number_Days > 1 Then
xNumber_of_Days = Number_Days
End If
End Function
' ================================================================================
' To calculate amount of time between time IN and OUT...
' Example: xChkedTimeIn = "12/02/2005 11:15:30 AM"
' xChkedDateAndTimeNow="12/03/2005 10:05:30 PM"
================================================================================
Function Actual_Time_Worked(xChkedTimeIn, xChkedDateAndTimeNow) 'Date_And_Time_Punched_In, Date_And_Time_Punched_In)
Dim In_Minute As Double
chk_Time_In = CDate(xChkedTimeIn)
chk_Date_And_Time_Out = CDate(xChkedDateAndTimeNow)
' Calculate the day name of the week in the year punched in.
' ------------------------------------------------------------
Day_Name_Of_The_Week = Format(chk_Time_In, "dddd")
' Calculate number of hours between the days.
' ------------------------------------------------------------
Number_hours = DateDiff("h", chk_Time_In, chk_Date_And_Time_Out)
' Calculate the day name of the week in the year punched in.
' ------------------------------------------------------------
Day_Name_Of_The_Week = Format(chk_Time_In, "dddd")
' Retrieve week # of the year from the system.
' ------------------------------------------------------------
Week_No_Of_Year = DatePart("ww", chk_Time_In)
' Month name of the year from the system.
' ------------------------------------------------------------
Month_Name_Of_Year = Format(chk_Time_In, "mmmm")
' Calculate minute
' ------------------------------------------------------------
calculated_Minutes = DateDiff("n", xChkedTimeIn, xChkedDateAndTimeNow)
In_Minute = Round((calculated_Minutes Mod 60), 2)
' Calculate total hours/minutes worked
' ===========================================================
HourWorked = Val(str(Number_hours)) & "." & Val(str(In_Minute))
' Calculate overtime hours worked
' ===========================================================
If Val(HourWorked) <> 0 Then
Actual_Time_Worked = HourWorked
End If
End Function
No comments have been posted about time in, time out, punched in, puched out calculate time, time spent. Why not be the first to post a comment about time in, time out, punched in, puched out calculate time, time spent.