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

subtracting time

Status
Not open for further replies.

rwn

Technical User
Dec 14, 2002
420
US
I have a report that requires subtracking the current time from when the shift started. (i.e current time 11:00:00am - shift started at 07:00:00) the value should be 3:00:00. Is there a way to obtain the total hours/minutes/sec??

Thanks
 
Get the difference in seconds using
Code:
DateAdd("s", Time1, Time2)
Then use DIVIDE and REMAINDER to get the number of whole minutes and hours. A neat example is given at faq767-3543.

[yinyang] Madawc Williams (East Anglia, UK). Using Windows XP & Crystal 10 [yinyang]
 
Madawc meant using datediff("s",datetime1,datetime2).

The FAQ should handle what you're after.

-k
 
I created three formula's. One is datetime1, it is (currenttime); another is datetime2, it is (Time (07,00 ,00 ) to represent the beginning of the shift; the third formula is current run time, it is (datediff("s",datetime1,datetime2). But at this third formula an error message is displayed...A number, currency amount, bolean, date, time, datetime, or string is expected here.....

I must be missing the obvious - my programming skills are light.
 
What are your actual formulas? What are the data types of your fields? Do you have a date field also?

-LB
 
The first formula is for shift start and it is a fixed time: Time(07,00 ,00 )
The second formula is to have the current time it is: CurrentTime

Both formula's are using the formulas within Crystal reports.

Then the third formula is to obtain the difference in minutes from the above two formulas. The third formula is the one displaying the error message.
 
When someone asks for the actual formulas, copy and paste the actual formulas, it means that they don't want to hear a description of them, they want to see the ACTUAL formulas.

You seem to have overlooked Madawcs reference to my FAQ (link in his post) to do what you wanted, so clikc the following link:

FAQ767-3543

-k

 
I did include the formulas and have also reviewed FA767-3543. But I'm not tring to find the diff in hhmmss, I'm trying to find the diff in minutes only. The first two formulas are from crystal reports the third is to find the difference in mm.

shift start = time(07,00,00)
present time = currenttime

timediff = (datediff("s",present time,shift start)...This last formula is the one that will not work.

 
You have to include dates to use datediff. If your shifts can cross days, e.g., 11pm to 7am, then you definitely should add actual date fields. Otherwise, you can write the formula like this:

datediff("n",datetime(currentdate,time(7,0,0)),currentdatetime)

This will give you results in minutes. It is unclear what kind of format you want to display this in.

-LB
 
Your first post stated:

Is there a way to obtain the total hours/minutes/sec??

Your last post states:

But I'm not tring to find the diff in hhmmss, I'm trying to find the diff in minutes only.

Perhaps you can understand now our confusion.

LBs formula should get you the results you seek, providing they are time fields, you should post technical information such as field types.

And if something doesn't work for you, post any errors, or why you believe it doesn't work.

-k
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top