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

need help to calculate dates!!

Status
Not open for further replies.

gavinjb

Programmer
Apr 24, 2003
106
GB
I am trying to do a calculation of the difference between dates I have Date-out and date-in and I need to display on my report the difference in Days,Hours and Minutes
(eg 2 03:47) between the two dates.

Thanks,

Gavin,
 
Here you go,

Numbervar datediff;
Numbervar days;
Numbervar Hrs;
Numbervar hours;
Numbervar Mins;
Numbervar Mns;
StringVar var;

datediff := ({@begin date}) - ({@end_date}); // Result in days
days := (Truncate(datediff));
hrs := (Datediff - days) * 24; //Convert Remaining to hours
Hours := (Truncate(hrs));
Mins := (hrs - hours) * 60; //Convert Remaining to minutes
Mns := (Truncate(Mins,0));

var := Totext(Abs(days), 0) + " " + Totext(Abs(hours),0) + ":" + Totext(Abs(Mns),0) ;


This is how I calculate in ver 7.x There could be a easier way in 9.0 which I am not much familiar with.
Hope this helps.
Good-Luck
 
I tried the formula out with Crystal 8.5 and it stops on datediff waiting for a variable. Do you know what could be the problem?

 
datediff is a resurved word. Use another name for the variable.

HTH


Bob Suruncle
 
Yes Datediff is a reserved word.It was not on ver 7.0.
Sorry about that.

Please modify the datediff to someother variable and it should work. Let us know how it goes.
 
Reebo's solution is far easier....the UFL returns exactly what is needed without any variables.

Software Sales, Training, Implementation and Support for Exact Macola, eSynergy, and Crystal Reports
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top