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

Subtracting Days / Hours / Minutes

Status
Not open for further replies.

IMALEGEND

Technical User
Feb 16, 2004
12
AU
Hi All

I have a large problem which I know you'll be able to help me with.

I have a date and a time in a report formula like this:

pwformatdate({date.data}) & " " & pwformattime({time.data}) which will return 01/11/2005 1:15pm.

I then have a subreport which returns a variable string which show 02/11/2005 11:30 am.

I need to show the diference between each date.

PLEASE HELP!!!!!!
 
In the subreport, create a formula like the following:

whileprintingrecords;
shared datetimevar subdate := cdatetime({table.stringdatetime});

Place this formula on the subreport somewhere. Then in a section of the main report below the one containing the subreport, use a formula like the following:

whileprintingrecords;
shared datetimevar subdate;
datetimevar maindate := cdatetime({table.stringdatetime});
numberVar dur := datediff("n",maindate,subdate);
numberVar days;
numberVar hrs;
numberVar min;
numberVar sec;
stringVar ddhhmm;

days := Truncate(dur/86400);
hrs := truncate(remainder(dur,86400)/3600);
min := round(remainder(dur/60,60));

ddhhmm := totext(days,"0")+" days, " +totext(hrs, "0") + " hours, " + totext(min, "0") + " mins";

ddhhmm

The conversion part of the formula is adapted from an FAQ from SynapseVampire to include days.

-LB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top