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!

Subtracting DateTime Fields

Status
Not open for further replies.

cacyf

Technical User
Nov 5, 2007
5
US
Sorry, I have searched the forums and could not find answer to this basic question.

I am using Crystal XI

I have a Start Time and End Time field in a report and would simply like to subtract the two. I have tried several expressions and have not gotten the exact number that I need. I do not know what I am doing wrong please help!

For example the Start Time would be 9:15am and the end time 10:45 am. I would like the result to be 1 hr 30 min.

Thanks!
 
If you use the following formula, you will get the difference in seconds. Then set the results to the variable "dur" in faq767-3543 in order to get a string result:

datediff("s",{table.starttime},{table.endtime})

This assumes that each field is a datetime.

-LB
 
These are only Time fields not Date/Time Fields and when I put the Starttime and Endtime fields in it says a Date field is required.
 
I believed your thread title. Anyway, change the formula to:

datediff("s",datetime(currentdate,{table.starttime}),datetime(currentdate,{table.endtime}))

This will work as long as your start and end times are within the same day.

-LB
 
Thank you that works perfectly. Is there any way to sum this field by running total?
 
If you want to summarize it, you could place the formula in the detail section->right click->insert summary->sum and choose the group or grand total level. If you want it displayed in the string format, use the faq and set the variable "dur" to:

sum({@yourformula},{table.yourgroupfield}) //at the group level

Or:

sum({@yourformula}) //at the grand total level.

-LB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top