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!

Date/Time calculation / conversion

Status
Not open for further replies.

CrystalMethod

Programmer
Mar 13, 2002
1
US
Hello all,
I am currently attempting to calculate the time difference( measured in Days,Hours,Minutes) between Scheduled and Actual delivery times. I first made this formula to return the difference:

//{@DelvTimeDeviance}=
// (CDateTime (CDate ({Loads.DelvDate}),CTime ({Loads.delvTime}))-
// CDateTime (CDate ({Loads.SchedDelv}),CTime({Loads.schedDelvTime}))) * 1440 ;

And then this formula to display in DD,HH,MM format:

Cstr(int({@DelvTimeDeviance}/1440),0)&":"&
cstr(int(({@DelvTimeDeviance}mod 1440) /60),0)&":"&
Cstr((((({@DelvTimeDeviance}mod 1440) /60) ) -
int(({@DelvTimeDeviance}mod 1440) /60) ) *60,0);

There is an issue however, if the delivery is made early returning a negative value. Not insurmountable, but before I start with all the math I am wondering if there a function in Crystal to display a Date/Time result in a DD,HH,MM format..? I appreciate your help!
 
Why not use the DateDiff function to determine the time difference? Like:
DateDiff ("s", {Loads.DelvDate}, {Loads.SchedDelv})
Which will return the seconds between the 2 times.

And the formula I common use to format like HH:MM:SS is:

WhilePrintingRecords;
NumberVar TotalSec := {Field};
//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,'')
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top