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

Adding up hours and minutes 1

Status
Not open for further replies.

gscheepers

IS-IT--Management
Jan 21, 2002
150
US
I have a DateTime field where the time element of the field is a 2 digit day, hour and minute. I would like to do is total the hours and minutes.

eg.

A person has three meetings one lasting an hour and two meetings lasting and halve hour each. Total for person should be 2 hours.
Gerhard Scheepers
BA - LETEC
 
You could convert that datetime field into seconds, add em up, then convert the seconds back into a time:

I use the following, however, there might be an easier way.

numbervar h:={your field in seconds};
3600*(h[1 to 2])) + 60*(h[4 to 5])) + (h[7 to 8]);

Hope this helps... Brian
 
Are you sure the data type of this field is a DateTime? True DateTime fields should also have Year, Month and seconds. see faq149-732. Ken Hamady, On-site Custom Crystal Reports Training & Consulting
Public classes and individual training.
Guide to using Crystal in VB
tek@kenhamady.com
 
Yes, the field has a Year, Month and seconds. I've tried the above formula, but it doesn't seem to work. Any other ideas???

Thanks! Gerhard Scheepers
BA - LETEC
 
If this is a true dateTime field, you can use the following functions:

Day (your fild)
Hour (your field)
Minute (your field)

to extract the three numbers. Then multiply them all to convert to seconds. You can total the seconds.

Then use the formula in faq149-243 to convert the seconds back to a formatted 'elapsed time' string if you want. Ken Hamady, On-site Custom Crystal Reports Training & Consulting
Public classes and individual training.
Guide to using Crystal in VB
tek@kenhamady.com
 
Thanks Ken! It works great! BUT, I don't want the total to run into days... instead I'd like the total to say ie. 8658 hours 50 minutes.

This is what it looks like at the moment:

WhilePrintingRecords;
NumberVar TotalSec := {@TotalTimeSec};
NumberVar Days := Truncate (TotalSec / 86400);
NumberVar Hours := Truncate (Remainder ( TotalSec,86400) / 3600);
NumberVar Minutes := Truncate (Remainder ( TotalSec,3600) / 60);
NumberVar Seconds := Remainder ( TotalSec , 60);

Totext ( Days, '00', 0,'') + ':'+
Totext ( Hours, '00', 0,'') + ':'+
Totext ( Minutes,'00', 0,'') + ':'+
Totext ( Seconds,'00', 0,'')

Thanks Gerhard Scheepers
BA - LETEC
 
Try this:

WhilePrintingRecords;
NumberVar TotalSec := {@TotalTimeSec};
NumberVar Hours := Truncate (TotalSec / 3600);
NumberVar Minutes := Truncate (Remainder ( TotalSec,3600) / 60);
NumberVar Seconds := Remainder ( TotalSec , 60);

Totext ( Hours, '00', 0,'') + ':'+
Totext ( Minutes,'00', 0,'') + ':'+
Totext ( Seconds,'00', 0,'') Ken Hamady, On-site Custom Crystal Reports Training & Consulting
Public classes and individual training.
Guide to using Crystal in VB
tek@kenhamady.com
 
Thanks! It works great!!! Gerhard Scheepers
BA - LETEC
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top