Click here to Skip to main content
15,884,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Good Day,

I am developing a Attendance System i am stuck in a problem
In My System Every Employee has assigned a shift and Work Span how many hours he can work .
let's Say Shift is General Shift Timings are
Start Time 09:00 ,Break Out Time 13:00,Break In Time 14:00 End time is 18:00
And the Work span is 34 hours for that Employee

Now on 21-Jun-2014 he comes on

Time Flag
09:00 In
13:00 Out
14:00 In
18:00 Out
19:00 In
Now again on 22-Jun-2014 he goes home on say
Time Flag
02:00 Out
09:00 In
13:00 Out
14:00 In
18:00 Out


Now if we add work span (34 hours ) to 21-Jan-2014 09:00 it will become 22-Jun-2014 19:00
Now this employee can work next day also


The problem which i am facing is I want
21-Jun-2014 his In Time is 09:00 And Out Time is
22-Jun-2014 02:00
so whatever he as worked between 21-Jun-2014 09:00 and 22-Jun-2014 02:00
Will go in 21-Jun-2014



And his next day punch will be for
22-Jun-2014 09:00
Out punch will be
22-Jun-2014 18:00


I have problem in finding In Time and out time
Posted
Updated 21-Jun-14 1:53am
v2

1 solution

There is an excellent article here on Code Project, a reference I should say (at least for me); here:
Time Period Library for .NET[^]
You should have a look at it, I would be surprised if you can't find anything in it that would help you fulfilling your requirement.
Cheers.
 
Share this answer
 
Comments
surajemo 21-Jun-14 8:03am    
Thank you for replying :).
I went through the article it describes all the classes and methods
But i have a written Stored procedure which finds in and out time ?
surajemo 23-Jun-14 1:20am    
Its a Engine that will run everyday and it will calculate the working hours for that day so the procedure start'like this

DECLARE @PreviousDate DATE=Dateadd(day, -1, @Date);
DECLARE @PrvWorkSpanTime AS TIME(7);
DECLARE @tblDates AS TABLE
(
pkid INT IDENTITY(1, 1),
workingdate DATE
)

INSERT INTO @tblDates
SELECT @PreviousDate
UNION ALL
SELECT @Date;

--loop over the dates and do the calculation for current day and previous day also because wee need to --handle night shift also
WHILE @WorkingDateCount >= @Counter
BEGIN
--get the one by one date
SET @Date =(SELECT workingdate
FROM @tblDates AS io
WHERE io.pkid = @Counter)



--get the shift according to shift schedule
SET @Shift_Via_ShiftSchedule =(SELECT TOP 1 fk_shiftid
FROM dbo.tblemployeeshiftdates
WHERE sa_date = @Date
AND fk_employeeid = @EmpId)

--default out time this will to get the out time
DECLARE @DefaultOutTime AS TIME(7)

--GET WORK SPAN HOURS FOR THAT EMPLOYEE
SET @WorkSpan=dbo.Fn_getworkspanhours(@EmpId);

DECLARE @prDATE AS DATE=Dateadd(day, -1, @Date);


--getting the previous day out time
EXEC @return_value = [dbo].[Get_previousdayouttime]
@Date = @prDATE,
@EmpID = @EmpID,
@FinalOutTime = @FinalOutTime output

--GET THE FIRST IN PUNCH
IF @Counter = 1
OR @Counter = 2
BEGIN
IF @FinalOutTime IS NOT NULL
BEGIN
SET @Intime= (SELECT Min(Cast(apdate AS DATETIME)
+ Cast(aptime AS DATETIME))
FROM [txnAcessPunches].[dbo].[atransaddpunch]
WHERE fkemapemid = @EmpId
AND apdate = @Date
AND ap_flag = 'In'
AND ( Cast(apdate AS DATETIME)
+ Cast(aptime AS DATETIME) ) > CONVERT(DATETIME, @FinalOutTime)); --AND CONVERT(DATETIME, @Date))
END
ELSE
BEGIN
SET @Intime= (SELECT Min(Cast(apdate AS DATETIME)
+ Cast(aptime AS DATETIME))
FROM [txnAcessPunches].[dbo].[atransaddpunch]
WHERE fkemapemid = @EmpId
AND ap_flag = 'In'
AND apdate = @Date)
END
END

EXEC @return_value = [dbo].[Usp_getshift]
@EmpId = @EmpId,
@InTime = @Intime,
@Shift_Via_ShiftSchedule = @Shift_Via_ShiftSchedule,
@ShiftID = @ShiftID output,
@Actual_ShiftInTime = @Actual_ShiftInTime output,
@Actual_ShiftOutTime = @Actual_ShiftOutTime output,
@Actual_BreakInTime = @Actual_BreakInTime output,

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900