[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
Solved

# Help time difference between two dates

Posted on 2013-01-25
Medium Priority
254 Views
Hi,

I have a table that has two dates

I need to find out the hour of the employees when they punch in and punch out

MONTHLY
WEEKLY
DAILY

Id        storeID       employeeID          PunchInDate                       PunchOutDate

1      9      13000505           2013-01-01 03:07:08.000      2013-01-01 06:32:32.000
2      9      13000505           2013-01-02 02:06:05.000      2013-01-02 05:31:31.000
3      9      13000505           2013-01-03 02:07:06.000      2013-01-03 05:31:32.000
4      9      13000505           2013-01-04 04:10:11.000      2013-01-04 06:39:40.000
5      9      6000247           2013-01-24 09:12:41.000      NULL
6      9      10000000           2013-01-24 09:12:41.000      2013-01-24 10:12:41.000
7      1      30           2013-01-25 00:00:00.000      2013-01-25 00:00:00.000
8      1      39           2013-01-25 00:00:00.000      NULL
9      1      54           2013-01-25 00:00:00.000      NULL
10      1      6000125           2013-01-25 04:10:11.000      2013-01-25 06:39:40.000

HOW CAN I CALCULATE THE HOUR THAT THE EMPLOYEE PUNCH IN AND PUNCH OUT
0
Question by:lulu50
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• 2

LVL 70

Accepted Solution

Scott Pletcher earned 2000 total points
ID: 38819560
DATEDIFF(MINUTE, PunchInDate, PunchOutDate) / 60.0 AS Hours_In
0

LVL 74

Expert Comment

ID: 38819562
datediff(hh,punchindate,punchoutdate) will give you whole hours
0

LVL 74

Expert Comment

ID: 38819579
to get hours/minutes/seconds

select totalseconds/ 3600 hours,
(totalseconds% 3600)/60 minutes,
totalseconds% 60 seconds
from
(
select datediff(ss, '2013-01-01 03:07:08.000',  '2013-01-01 06:32:32.000')as totalseconds
) as x
0

Author Closing Comment

ID: 38821725
Thank you
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.
###### Suggested Courses
Course of the Month13 days, 18 hours left to enroll