Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Time and Attendance Lunch Calculation

Status
Not open for further replies.

TJIT

MIS
Jan 29, 2009
19
US
I have two fields in a subreport that display punches for each employee for each day of the week. If, and only if, that employee takes a lunch, there will be 4 punch times listed. I need to subtract the first "out" punch from the second "in" punch.

{V_TA_PREPOST.START_TIME} and
{V_TA_PREPOST.END_TIME}

If someone takes a lunch their punches for the day would look like so:

in out
7:00 am 11:30 am
12:00 pm 3:00 pm

I created a formula called "lunchflag" that determines whether there are four punches:

If DistinctCount ({V_TA_PREPOST.START_TIME})= 2 and DistinctCount ({V_TA_PREPOST.END_TIME})= 2 then "1"

Else ""

Now what I (think I) need to do is make another formula and take the two middle punches and subtract them which will result in the amount of time they took for lunch:

"If @lunchflag = 1 then blahblahblah"

It's the "blahblahblah" part where I'm stuck. How can I tell the formula to only subtract the two "middle" punches?
 
//{@lunch}:

If {@lunchflag} = 1 and
{table.employee} = previous({table.employee}) then
{table.in} - previous({table.out})

-LB
 
previous" worked! I also discovered the magic of DateTimeVar

This is what I ended up with:

If {@lunchflag} = "1" then

Local DateTimeVar d1 := {V_TA_PREPOST.START_TIME};
Local DateTimeVar d2 := PREVIOUS({V_TA_PREPOST.START_TIME});
Local DateTimeVar d3 := {V_TA_PREPOST.END_TIME};
Local DateTimeVar d4 := PREVIOUS({V_TA_PREPOST.END_TIME});

DateDiff ("n", d4, d1)

I realize I don't need d2 or d3 but it helps me to keep track.

Thank you very much for your response, LB.
 
You shouldn't really use variables unless necessary, and there is no real need for them in this case. Not that they hurt, but they are an overcomplication in my opinion.

-LB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top