Need Help-Employee Time Clock

I am trying to write a simple time clock to include in an app I am creating. Have not worked with time and dates too much. Just looking for an easy way for an employee to keep track of her time. Will have a clock in, clock out button and a label that displays the total time worked between the 1st and 15th and the 16th to 31st. Any help on where to start would be appreciated. Thanks.

I wrote this years ago to tell me the time (even seconds) between two dates. You can input two dates either as dates or as tab-separated text. It will hopefully give you what you want and there may be a much shorter or easier method.

[code]Protected Function getDateDifferenceWAD(startDate As date, endDate As date, sourceDates As String = “”, includeTime As Boolean = True) as String
'returned the time difference between two strings as a text description
Dim tempReturn As String
Dim tempDate As New Date
Dim tempYears, tempMonths, tempDays, tempHours, tempMinutes, tempSeconds As Integer 'tempInt

if startDate = nil then 'if the Date values are nil then check the string Dates
startDate = commonDates.getDateTimeWAD(NthField(sourceDates, chr(9), 1))
if startDate = nil then Return sourceDates

endDate = commonDates.getDateTimeWAD(NthField(sourceDates, chr(9), 2))
if endDate = nil then endDate = New Date

if endDate = nil then endDate = New Date
end if

if startDate = nil or endDate = nil then Return sourceDates

tempDate.TotalSeconds = abs(endDate.TotalSeconds - startDate.TotalSeconds) 'tempInt 'tempDouble

tempYears = abs(tempDate.Year - 1904)
tempMonths = abs(tempDate.Month - 1)
tempDays = abs(tempDate.Day - 1)
tempHours = abs(tempDate.Hour)
tempMinutes = abs(tempDate.Minute)
tempSeconds = abs(tempDate.Second)

if tempYears <> 0 then
tempReturn = tempReturn + str(tempYears)
if tempYears = 1 then tempReturn = tempReturn + " year " else tempReturn = tempReturn + " years "
end if
if tempMonths <> 0 then
tempReturn = tempReturn + str(tempMonths)
if tempMonths = 1 then tempReturn = tempReturn + " month " else tempReturn = tempReturn + " months "
end if
if tempDays <> 0 then
tempReturn = tempReturn + str(tempDays)
if tempDays = 1 then tempReturn = tempReturn + " day " else tempReturn = tempReturn + " days "
end if
if includeTime then
if tempHours <> 0 then
tempReturn = tempReturn + str(tempHours)
if tempHours = 1 then tempReturn = tempReturn + " hour " else tempReturn = tempReturn + " hours "
end if
if tempMinutes <> 0 then
tempReturn = tempReturn + str(tempMinutes)
if tempMinutes = 1 then tempReturn = tempReturn + " minute " else tempReturn = tempReturn + " minutes "
end if
if tempSeconds <> 0 then
tempReturn = tempReturn + str(tempSeconds)
if tempSeconds = 1 then tempReturn = tempReturn + " second " else tempReturn = tempReturn + " seconds "
end if
end if

'tempReturn = commonStrings.getRemoveExcessWAD(tempReturn, " ") 'Ignore this

if endDate.TotalSeconds - startDate.TotalSeconds < 0 then tempReturn = “-” + tempReturn

Return tempReturn

End Function

Start by creating a database to hold the records
Maybe at the start of the day, when they clock on, record this info in the database:

Employee Ref / date / Clock In Time

Fields for clock off time, cost code(area worked), absence reason can exist but be blank at this stage.

When they clock out, update the row for that employee that has today’s date and no clock out time, with the clock out time.

If someone fails to clock out, a timer can update the record in some way.

The time worked is clock out minus clock in time, but likely there will be min/max times and rules about 15 minutes late to apply.

In the database you can store the employment as an Integer of the number of seconds worked each day. Later add up these sets of seconds, then turn that into a days/hours/minutes display for reporting.

If you want to outsource the design/programming of this module of you app… let me know… .I have plenty of time (pun) and am a very experienced Xojo and Database programmer

We use the DateDifferenceMBS in our time clock system. But having a query in your database do the calculations usually works too.

Thank everyone for the help! A lot to go off of here and its been a big help to point me in the right direction. Thanks David for the code. Ill see if I can use it for what Im doing.

Try this litte app “TimeClock”

TimeClock for Windows
TimeClock for macOS

No database, only a simple file: