Skip to main content
Participant
November 21, 2009
Question

Datediff for Time Clock

  • November 21, 2009
  • 5 replies
  • 2602 views

Hello.  I am having a problem putting my mind around how this works.  I am working on creating a time clock. When a person clocks in each day an entry is inserted into the database.  As they continue to clock in or out that day entry in the database is updated to log the time/date stamp up to 6 entries.

EmployeeIDTimeClockIDTimeEntryReg1TimeEntryVacTimeEntrySickTimeEntryHolTimeEntryOtherTimeEntryOtherReasonSPROverrideSPROverrideDateTimeEntryReg2TimeEntryReg3TimeEntryReg4TimeEntryReg5TimeEntryReg6
10111/12/2009 5:51:31 PMNULLNULLNULLNULLNULLNULLNULLNULL

When I call the query I can get the cfoutput to loop through each record and display each of the log in/out's.  What my problem is is that I am not able to do a datediff to figure out how many hours/mins that employee has worked between the clock in and out. I get an error every time that says my date is invalid. I am guessing that it is because the variable is unable to determine which record is which since there are multiple records.  Could someone PLEASE help me get my head around how to display the time worked correctly?  Thanks.

<table width="800">
<cfoutput query="selectPerEmployeeTimeClockEntry">
  <tr>
   <td width="50" nowrap>
    #DateFormat(TimeEntryReg1, "dddd mm/dd")#
   </td>
   <!--- <td width="50" nowrap>
    #TimeFormat(TimeEntryReg1, "hh:mm:sstt")#
   </td>
   <td width="50" nowrap>
    #TimeFormat(TimeEntryReg2, "hh:mm:ss tt")#
   </td>
   <td width="50" nowrap>
    #TimeFormat(TimeEntryReg3, "hh:mm:ss tt")#
   </td>
   <td width="50" nowrap>
    #TimeFormat(TimeEntryReg4, "hh:mm:ss tt")#
   </td>
   <td width="50" nowrap>
    #TimeFormat(TimeEntryReg5, "hh:mm:ss tt")#
   </td>
   <td width="50" nowrap>
    #TimeFormat(TimeEntryReg6, "hh:mm:ss tt")#
   </td>

This topic has been closed for replies.

5 replies

June 2, 2011

Hi dogooder64012

I'm new to adobe and i'm trying to create a time stamping login logout form for employees so i can track their time.

The old fashioned clunky time clock that punches the card is dying.

Would it be possibe to email or show me a sample of how you got your's to work?

It would help out a lot.

if anyone else has a sample or point me in the right direction that would be awesome also.

Thank you!

soynv@yahoo.com

BKBK
Community Expert
Community Expert
June 4, 2011

soynv wrote:

Hi dogooder64012

I'm new to adobe and i'm trying to create a time stamping login logout form for employees so i can track their time.

The old fashioned clunky time clock that punches the card is dying.

Would it be possibe to email or show me a sample of how you got your's to work?

It would help out a lot.

if anyone else has a sample or point me in the right direction that would be awesome also.

I would advise you to start your own thread. I am sure you will then have a better chance to get assistance.

Participant
November 25, 2009

Hello.

Thanks for your responses. I made the database modifications so that the clock in entries are seperate from the clock out entries as see below:

Employee IDTimeClockIDTimeEntryReg1INTimeEntryReg2
10111/12/2009 17:5111/12/2009 19:51
10211/12/2009 20:1711/12/2009 22:17

However, I am still not able to get the data from the database to display in columns nor can I get the times to calculate in the number of hours/minutes there are between clocking in and out.

I appreciate any help you can provide.  Thanks.

Inspiring
November 25, 2009

One problem at a time.  We'll do the interval between clocking in and out.

Is TimeEntryReg1IN to time in and TimeEntryReg2 the time out?  What data type are they in your db?  What db software are you using?

Different db's have different ways of calculating these intervals.  You can look your's up by googling "your db date functions".

Participant
November 25, 2009

Yes, the column "TimeEntryReg1IN" is to time in and "TimeEntryReg2" is to time out. They both have the data type of "datetime".  And, I am using "myLittleAdmin for MS-SQL Server".

I am using just a basic query to get started which is:

SELECT *
FROM TimeClock tc, Employee e
WHERE tc.EmployeeID = form.EmployeeID AND
      tc.EmployeeID = e.EmployeeID

Thanks for your help!

Inspiring
November 23, 2009

I agree with the comment that the database-design could be considerably improved.

Each time the user punches-in, he creates a new punch-record, of a particular type (e.g. "sick," "holiday," "regular") with a specified starting-time and a NULL ending-time.  When he clocks out, we expect to find that the most-recent record has a NULL ending-time and so we update it.  (But the possibility of a "missing punch" must also be considered!)

The resulting single record describes one contiguous unit-of-time.  The table is indexed by {employee_id, start_timestamp} so that we can instantly locate the clock-in record to update when we clock-out.

I do offer the slightly-dissenting opinion that the "date" and "time" columns should be one... a "datetime" data-type that incorporates both the date and the time.  After all, people do clock-out "after midnight."  (And I'm entirely sure that Ian would agree with that.)

Also, of course, you'll use <cftransaction> tags to make the operations fully atomic.

ilssac
Inspiring
June 3, 2011

TLC-IT wrote:


After all, people do clock-out "after midnight."  (And I'm entirely sure that Ian would agree with that.)

You JUST HAD to make me remember the year that I worked two graveyard shifts from 8pm to 4am. While at the same time working two day shifts (8am to 4pm) and one swing shift (12:00 noon to 8pm) every WEEK.  Goodness that was a hell of a year.

BKBK
Community Expert
Community Expert
June 4, 2011

ilssac wrote:

TLC-IT wrote:


After all, people do clock-out "after midnight."  (And I'm entirely sure that Ian would agree with that.)

You JUST HAD to make me remember the year that I worked two graveyard shifts from 8pm to 4am. While at the same time working two day shifts (8am to 4pm) and one swing shift (12:00 noon to 8pm) every WEEK.  Goodness that was a hell of a year.

You're responding to post that is 18 months old! Even then you're not providing an answer or something of the sort. What the heck is going on here, man?

BKBK
Community Expert
Community Expert
November 21, 2009
What my problem is is that I am not able to do a datediff to figure out how many hours/mins that employee has worked between the clock in and out.

<!--- start and end times --->
<cfset start_time = timeformat("09:34:56", "hh:mm:sstt")>
<cfset end_time = timeformat("12:01:33", "hh:mm:sstt")>

<!--- to form datetime values, add today's date to start and end times --->
<cfset start_datetime = parsedatetime(dateformat(now(), "yyyy-mm-dd") & " " & start_time)>
<cfset end_datetime = parsedatetime(dateformat(now(), "yyyy-mm-dd") & " " & end_time)>

<!--- use datediff() to calculate difference between datetime values --->
<cfset time_diff_hr = datediff("h",start_datetime,end_datetime)>
<cfset time_diff_min = datediff("n",start_datetime,end_datetime)>
<cfset time_diff_sec = datediff("s",start_datetime,end_datetime)>

time difference in hours: <cfoutput>#time_diff_hr#</cfoutput><br>
time difference in minutes: <cfoutput>#time_diff_min#</cfoutput><br>
time difference in seconds: <cfoutput>#time_diff_sec#</cfoutput><br>

<!--- time difference in hours, minutes, seconds --->
<cfset hours = int(time_diff_sec/3600)>
<cfset minutes = int(time_diff_sec/60)-hours*60>
<cfset seconds = time_diff_sec - hours*3600 - minutes*60>

<br><br>
Time difference:<br>
hours: <cfoutput>#hours#</cfoutput><br>
minutes: <cfoutput>#minutes#</cfoutput><br>
seconds: <cfoutput>#seconds#</cfoutput>

ilssac
Inspiring
November 21, 2009

Are we allowed to suggest a database design change to make this work much easier?

If you had a more normalized database with the start time and endtime for each work period as a seperate record rather then repeating fields like you currenlty have them.  Repeating fields are a sure sign of data that could be noralized.

Thus if you had a workPeriod table that looked something like this

EmployeeID
DateStarttimeEndtime
1231/1/200110:3012:00
1231/1/200112:3014:00
1231/1/200114:1516:00
1231/2/20018:0010:30

Then it would be a fairly basic task to query this timeworked table join it to the employee and other relevant tables and find out how long an employee worked.