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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Easy way to Do Time

Status
Not open for further replies.

shobud

Programmer
Feb 4, 2002
4
US
I am having some trouble setting up a program that would allow me to just enter time in, in hours and minutes and enter time out, in hours and minutes and then do calculations on them somewhat like a time clock. Any help would be appreciated.
Thanks
 
Since there is no native Time variable or field type, you have two+ choices. You can use the DATETIME type and just ignore the date if you never cross days in your in / out calculations. DATETIME arithmetic is easy - it works in seconds. Or you can store your hours and minutes in one or two character fields (or one numeric field). Then it's not that tough to build the routines to calculate the differences between values. The ultimate 'best answer' is really dependent on your calculation and reporting needs.

Rick
 
Check out Sys(2). It converts a time string "10:31:20" into a integer 37880 that represents the number of seconds since midnight. You can then do math on the 2 values.

So You Will need 4 data entry blocks
Hr1, Mn1
Hr2, Mn2

start = sys(2, alltrim(hr1) + ":" +alltrim(Mn1))
finish = sys(2, alltrim(hr2) + ":" + alltrim(Mn2))

Clock Time = finish - start

This gives you the number of seconds on the clock,
All You have to do then is divide by 360 to get the hours.
Divid the remainder by 60 to get the number of minutes.
the remainder of that is the number of seconds.


David W. Grewe
Dave@internationalbid.com
 
Rick and David,
Thanks for the information, I appreciate it very much.
Dan
 
Of course that's divide by 3600 to get the hour, not 360.

Dave Dardinger
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top