473,387 Members | 1,485 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

hours worked

lee123
556 512MB
i have a form with timestarted and timeended and i have asked this question before but in access the way they did it was in a query but i don't know how to work the query in vb6 so maybe one of you people can help me i am trying to figure out how i can get the hoursworked on my form from the fields timestarted & timeended i thought you could do this:

Expand|Select|Wrap|Line Numbers
  1. Private Sub HoursWorked_Change()
  2. Dim Hoursworked as integer
  3.  
  4. Hoursworked = (timeended) - (timestarted)
  5.  
  6. End Sub
but as as you have guessed it didn't work, so if anyone knows how to do this please help!!!!

lee123
Mar 2 '08 #1
4 1160
Killer42
8,435 Expert 8TB
Use the DateDiff() function.
Mar 3 '08 #2
lee123
556 512MB
Hey killer42, thanks for that. i have done this it works but if i have a wierd time in there like 12:15pm to 2:45pm it doesn't give me all the time it just gives me the hours the way i have done this is this:

Expand|Select|Wrap|Line Numbers
  1. Private Sub HoursWorked_GotFocus()
  2.  
  3.     HoursWorked = DateDiff("h", TimeEnded, TimeStarted)
  4.  
  5. End Sub
please tell me if i did this right or is there a way i can fix this? oh i also have an amount due field on this how would i calculate the hoursworked times a rate such as, if i worked 3 hr and the rate is $10.00 how would i get the amount due to say $30.00

lee123
Mar 3 '08 #3
jamesd0142
469 256MB
Try something like this:


Expand|Select|Wrap|Line Numbers
  1.     Dim HoursWorked As String
  2.         Dim minutesworked
  3.         Dim TimeStarted As Date = "02/3/2008 12:58:22 PM"
  4.         Dim TimeEnded As Date = System.DateTime.Now
  5.  
  6.         minutesworked = DateDiff(DateInterval.Minute, TimeStarted, TimeEnded)
  7.         HoursWorked = CInt(minutesworked) / 60
  8.  
  9.         TextBox1.Text = HoursWorked
  10.  
Mar 3 '08 #4
Killer42
8,435 Expert 8TB
To expand slightly on James's example...

Expand|Select|Wrap|Line Numbers
  1. Dim TotalMinutes As Long
  2. Dim HoursWorked As Long
  3. Dim MinutesWorked as Long
  4.  
  5. TotalMinutes = DateDiff("n", TimeStarted, TimeEnded) ' Note, VB6 format
  6. HoursWorked = Int(TotalMinutes / 60)
  7. MinutesWorked = TotalMinutes - 60 * HoursWorked
  8.  
Mar 4 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: sg_s123 | last post by:
============================================================================ 02-Feb-04 03-Feb-04 Staff Staff 0800hr- 1300hr- 1700hr- 1900hr- 0800hr- 1300hr- 1700hr- 1900hr- Number...
5
by: Rebecca Smith | last post by:
I'm building log book to keep track of a racers stats during a long ultra marathon race. Things such as time on the bike, time off, H20 intake, electrolytes and the like. When I say long I mean...
1
by: serge | last post by:
Right now the database I am working with is storing time in an Integer data type and is storing the time value in seconds. The application does not allow entering seconds. It accepts minutes and...
22
by: Drum2001 | last post by:
I have a table that tracks employee times. I have a column (Date/Time). Users, through a form, enter how long it takes them to complete a task. For example, 03:45 = 3 hours and 45 mins. I am...
1
by: Brett | last post by:
Does anyone know how to calculate hours that go over 24? I am tracking how many hours & seconds our production keyers work everyday. When I run a query for a length of time that a given employee...
1
by: deena22 | last post by:
hello, i'm using 'Access database' and VB 6.0. My database is named ' timesheet' and it contains a table named 'tabletimesheet'. The table contain the following fields: 'staffname, stafftype,...
6
by: richbneal | last post by:
I really like the site so far and this is my first post. I have looked through some of the archives with no luck. I have also read the posting guidelines and will do my best to be clear and accurate...
2
by: mar10 | last post by:
i have TIME WORKED stored as minutes - I'd like to convert this to days,hours,minutes. I'm currently converting to hours and minutes but have not had success adding the days portion to the...
9
by: brendanmcdonagh | last post by:
Hi, I am designing a project for my friend as I am just a week old baby to vb and want to implement what I've learnt so far. She wants to be able to put start time, end time and lunch for each...
10
by: imran akhtar | last post by:
#Workers in a company are paid £8 per hour for each hour they work up to a #basic working week of 40 hours, and £12 an hour for any overtime they work. #Write a program that asks the user to enter...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.