Question How do you get the difference of time in and time out?

mallows

New member
Joined
Aug 23, 2008
Messages
3
Programming Experience
Beginner
Hello, im a student in the philippines and im making a simple program in vb but having problems in getting the difference of time in and time out. what is the correct syntax in getting the difference of time in and time out? I want to display the total number of hours work in a day. By subtracting the time in and time out of an employee you get the number of hours work right? My problem is how do you encode this in VB? really have no idea on this one. Any help will be appreciated..
 

kasyoki

Member
Joined
Jun 21, 2008
Messages
6
Programming Experience
3-5
hi mallows

heres the solution.


Dim a As Date
Dim b As Date
Dim c
a = "15:00:00"
b = "17:00:00"
c = DateDiff(DateInterval.Hour, a, b)
MessageBox.Show("difference in hours " & c)

output is 2

use of a function called datediff

Nice tyme
vincent from kenya(vincentkasyoki@yahoo.com)
 

cjard

Well-known member
Joined
Apr 25, 2006
Messages
7,052
Programming Experience
10+
Vincent;

implicit conversion of string-> date
use of DateDiff legacy function
neglecting to include the date on the time merely defaults the date to min value..

in short, that code is worse than awful. Please look up DateTime.ParseXXX methods, and the TimeSpan structure ;)
 
Top Bottom