Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calculating Time

Status
Not open for further replies.

ptrifile

Technical User
Aug 10, 2004
457
US
I created a very simple form that a user clicks a button and it records the date and time of when they clicked. When a user wants to login they choose their name and then click the button. When they want to log out they do the same. When i run a report it lists the times and names just as I want and i just use the first one as the login time, the second for logout time, third for login, fourth for logout etc..etc.. My question is this, is it possible to create some sort of formula or code to count the total hours worked while using this type of format? Any help or suggestions are appreciated.

Thanks!

Paul
 
Can you provide some sample records and how you would like your result to display? Your description doesn't suggest if these are all in one record or multiple records. It would be nice to know the table and field names.

Duane
MS Access MVP
[green]Ask a great question, get a great answer.[/green]
[red]Ask a vague question, get a vague answer.[/red]
[green]Find out how to get great answers faq219-2884.[/green]
[blue]Ask me about my grandson, get a grand answer.[/blue]
 
While it is relatively easy to do the calc, it is subject to problem(s). In particular, the alternateing assumption of In/Out designation for the times. It would, perhaps, be better to employ some mechanisim to force (or capture) the User log-in (and the fact that it is a "log-in) on startup and just have the button record (and 0again- denote the log-out action.

If / when a system crashes or there is a network disconnect, your assumption of alternating log[In | out] will be in-accurate. Another instance could occur if a user starts multiple copies of the db. There are probably more, but this should be sufficient to illustrate the possability.





MichaelRed


 
I have never found a easy way to do date math, but this is what I use.

I basically convert all of the time to minutes.
the field with the times are [starttime] & [endtime]

Use these fields in a query
starthours:=Format$([starttime],"hh",0,0)
endhours:=Format$([endtime],"hh",0,0)
startminutes:=Format$([starttime],"nn",0,0)
endminutes:=Format$([endtime],"nn",0,0)
hours:=[endhours]-[starthours]
minutes:=[endminutes]-[startminutes]
totalminutes:=ttmm:=(([hours]*60)+[minutes])

You can now add your minutes together from different shifts or multiply them by some factor.
Then divide the minutes by 60 to get hours & minutes again
 
there are several to numerous discussions of date/time "math" in these fora. The concept is simple, and is easily understood by most. Data-time data type (values) are just 'strangely' formatted (arranged) double (floating point) data types. The only 'trick' to their use in normal arithamatic is knowing the format. This, as noted, is discussed extensively in these fora.





MichaelRed


 
dful,
Just a quick, generic nudge... the Format$() function you are using converts numeric type values to string/text. You shouldn't attempt to do any math calculations with strings.

Duane
MS Access MVP
[green]Ask a great question, get a great answer.[/green]
[red]Ask a vague question, get a vague answer.[/red]
[green]Find out how to get great answers faq219-2884.[/green]
[blue]Ask me about my grandson, get a grand answer.[/blue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top