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

How can I subtract a date/time field?

Status
Not open for further replies.

KZOG

MIS
Sep 30, 2003
9
US
I know this sounds kinda like a dumb question, but here is the deal.

I have two date/time fields. This is my formula

({ADT_PatientVisit.AdmitDateTime} - {MPVisit.DateTime})

The data looks like this (example):

MPVisit DateTime AdmitDateTime DateTimeDiff
9/22/03 9:58AM 9/22/03 10:39AM 0.03

I tried to use the format field for the formula and I still don't get the correct data. How can I subtract accurate date/time fields?

Thanks!
 
I've seen some unpredictable wonky behavior calculating elapsed times through a straight mathematical operation. The DateDiff() function always seems to perform correctly, so that's what I've come to use by default.
 
Unfortunately, I cannot use the DateDiff function because I'm on Crystal 7.0. Do you have any other suggestions?
 
Go to the Crystal Decisions website & access the knowledge base. Then, do a search for "date time difference", specifying CR 7 (alternately, search for "ufldtdif.exe" and/or "timediff.zip"). Both are collections of CR7-friendly functions that will let you do all sorts of date/time arithmetic.

If you get a change to move to CR 8.x, brave the fires of hell to do so. By themselves, the upgrades/additions to the function library are worth the price. I'm not trying to tease, but if your boss will consider it, tell him it's a night-to-day difference between the versions.
 
I have a link on the LINKS page of my web site that allows you to download some of the v8 date functions for v7.

I also have a formula on my FORMULAS page that shows how to convert a number of seconds in to an elapsed time string.

Ken Hamady, On-site Custom Crystal Reports Training & Consulting
Public classes and individual training.
Expert's Guide to Formulas / Tips and Tricks / Guide to Crystal in VB
- tek@kenhamady.com
 
I created a formula using this logic:
DTSToTimeString(DateTimeDiff({MPVisit.Created},{ADT_PatientVisit.AdmitDateTime}))

and it returned this:
1 Hour(s), 8 minute(s), 55 second(s) ----this is good but I want to convert it to 1:08:55. How can I do this?
 
I have a FAQ in this forum will convert a time to HH:MM:SS:

faq767-3543

Bascially you would use the datediff in seconds.

-k
 
I upgraded to Crystal 8.5. Thanks it worked! Yippie!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top