Click here to Skip to main content
15,868,016 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi Good day to all developers here.

First thing i would like to know is how can i calculate the number of work hours. I am using VB.Net 2008, MySQL as my Back end and Crystal Reports of .Net for Attendance reporting purposes

Assuming We have a database fields of Name, Date, Time_in & Time_out
and the values are,

Name: Joshua
Date: 5/17/2012
Time_in: 1:30 AM
Time_out: 5:30 AM

Expected Result Should Be: 4


I managed to display the name, Date, Time_in and Time_out in Crystal reports however i do not really know how to calculate the work hours i tried formula fields and dateandtime functions but it doesn't work for me.

Can anyone give me a hand for me to have a good start

Thanks
Posted
Updated 16-May-12 7:44am
v2

Crystal should support the DateDiff function so you could try to set up the formula like
DateDiff ("h", {Time_in}, {Time_out})
 
Share this answer
 
Comments
VJ Reddy 16-May-12 19:58pm    
Succinct and to the point. 5!
Wendelius 17-May-12 4:26am    
Thanks :)
JMAM 16-May-12 20:36pm    
Hi,

First of all i would like to thank you for taking a time answering this post.

i tried

DateDiff ("h", {Time_in}, {Time_out})

It works, but when Time_in starts at PM and Time_out is at AM
the out gives me a negative values
Example when user have a graveyard shifts

Time_in 8:00 PM
Time_out 3:00 AM

Result would be -17
Wendelius 17-May-12 4:27am    
Yes, that's correct if you have only time portion in the variable. If the variables would include the date, the result should be correct. For example:

Time_in 5/16/2012 8:00 PM
Time_out 5/17/2012 3:00 AM
JMAM 17-May-12 8:16am    
Thanks once again but sir i am using MySQL and the values that i have in the database is

Time_in : 2012-05-17 20:31:08
Time_out : 2012-05-17 03:10:16
and i did exactly what you said but the result was "-17"

Thanks for sharing your knowledge and time
If put the time in and time out into DateTime instances in VB.Net, you can just subtract them.
 
Share this answer
 
Comments
JMAM 16-May-12 20:43pm    
Hi thanks for the reply however i do know how to do this can you give me a sample code using Time_in and Time_out

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

  Print Answers RSS


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