Employee Name & Hours Worked for The Day

May 25, 2008 5 Replies

Hi all,



I'm trying to determine the name and time that employees work on a certain day. So I'd like to see the employee name next to the hour of the day like this:



Name, TimeIn, TimeOut Yvonne, 11, 15



select c.name, datepart([hour], t.TimeIn) as TimeIn, datepart([hour], t.TimeOut) as TimeOut



--select c.name, t.timein, timeout from cashier c, timeclock t where t.cashierID = c.id and convert(varchar(10),t.DBTimeStamp,110) = '05-05-2008'



I have trouble with the date convert me thinks. Not too familiar with date format conversions in SQL Server.



Any suggestions?


Hi Jerry -

Can something like this work for you?

select c.name, datepart([hour], t.TimeIn) as Hour_TimeIn, datepart([hour], t.TimeOut) as Hour_TimeOut from cashier c inner join timeclock t on c.id = t.cashierid where t.timein between '1/3/2008' and '1/4/2008'

-- this would show you at what hour clock ins and clock outs took place (for january 3 2008) -- hope this helps....

"Jerry" wrote:

This works. So how do I convert datepart to have the dd/mm/yyyy and the hh? I really want it to be

05/13/2008 10:00 05/13/2008 11:00

for the time format.

Try it without converting the datatype....you'll get date and hr/min on both the clock in and the clock out - hope this helps.....

select c.name, t.Time> > > Hi Jerry -

I only want the hour, I don't want minutes or seconds.

05/13/2008 10 05/13/2008 11

OK - try it this way - though I split it into two columns since I'm not sure how to "cut off" the minutes/seconds from the datetime datatype...maybe a more experienced SQL user will post that solution for you with a "right trim"

- hope this helps....

select c.name, convert(char(11),t.timein) as DateIn, datepart([hour], t.TimeIn) as Hour_TimeIn, convert(char(11),t.timeout)as DateOut, datepart([hour], t.TimeOut) as Hour_TimeOut from cashier c inner join timeclock t on c.id = t.cashierid where t.timein between '1/3/2008' and '1/4/2008'

"Jerry" wrote:

datepart([hour],

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required