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

Time Differences

Status
Not open for further replies.

Nitrodamsel

Programmer
Mar 10, 2010
9
PH
I don't know how I can subtract two different time.

Well I created something but it doesn't work.

Example I wanted to Subtract

7:30 AM to 5:30PM i wanted to get the difference
of the time, so the answer is 10 Hours.

How can I do that?
 
Can we assume that the times are held in datetime variables or fields? If so, a simple subtraction will give you the difference, in seconds.

Example:

Code:
t1 = datetime(2010, 3, 10, 7, 30, 0)
t2 = datetime(2010, 3, 10, 17, 30, 0)
? t2 - t1

That will give you 36000. To get it to hours, divide by 3600.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
I have it integrated to my form, Uhmm it is automatically generated I give you an example Im making a Payroll System

TIME-IN
3/10/2010 7:30:00 AM

TIME-OUT
3/10/2010 5:30:00 PM

How can I subtract that?


 
You need to explain the context in more detail. You say it's "integrated" in your form, which is "automatically generated". That tells me nothing about how you are storing the times.

Have you tried my suggestion? What exactly happened when you did?

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
The data is stored in the table with a datatype of DATE/Time

I have created a textbox that has a controlsource in the table where i put the TIME-IN and TIME-OUT


(I have tried what you told to me and it works.. but Actually the time is generated by DATETIME()


I have my sample program attached
 
 http://www.mediafire.com/?ttjjglnn32z
You say:

The data is stored in the table with a datatype of DATE/Time

That's what I was assuming.

I have created a textbox that has a controlsource in the table where i put the TIME-IN and TIME-OUT

I assume you mean two textboxes: one for time in and one for time out.

If so, you simply need to subtract the value of one of the textboxes from the value of the other:

Code:
nHoursWorked = ;
  ROUND( ;
    (thisform.txtTimeOut.Value - thisform.txtTimeIn.Value)/3600), 0)

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
Code:
timein = datetime(2010,3,10,7,30)
timeout = datetime(2010,3,10,17,30)
totalSeconds = m.timeout - m.timeIn

If those values are character and difference is assumed to be less than 24 hours:

Code:
timeIn = '7:30AM'
timeOut = '5:30PM'
totalSeconds = ctot(m.timeOut) - ctot(m.timeIn)



Cetin Basoz
MS Foxpro MVP, MCP
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top