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

Subtracting Discharge time from Admit time 2

Status
Not open for further replies.
Feb 6, 2004
7
US
I had to convert time from a # and I used this formula:
time(int({table.timeint}/100),remainder {table.timeint},100),0)

Now I need to subtract the time a patient was discharged for the time they came in. Example:

Admit Discharge Should =
7:50am 10:40 2:50
7:51am 10:50 2:59
5:02pm 6:28pm 1:26
6:49pm 11:29pm 4:40

I have tried: time(int({ERLOG.DTIME}/100),remainder({ERLOG.DTIME},100),0) -
time(int({ERLOG.ATIME}/100),remainder({ERLOG.ATIME},100),0)

please help
 
Assuming that there are no overnight stays, or multiple days, as you'd need a datetime field then...your formula is fine.

You just need a method to convert it to a time again as the result is in seconds:

faq767-3543

-k
 
OK.. I do have overnight stays what would I need to add? Date - date = 2400?

Thanks for your help
 
Here's another way to do it, using minutes instead of seconds:

TimeValue(int(datediff("n",{ERLOG.ATIME},{ERLOG.DTIME})/60), datediff("n",{ERLOG.ATIME},{ERLOG.DTIME}) mod 60,0)

Then, format it as necessary.

-dave
 
Perhaps you need to sit and think about what you need before posting again as you've also started another thread, without mentioning dates, and without anything technical.

Consider the process and what the time fields represents. Is it truly a time field, or is it the elapsed time since another time? Since you're subtracting them, I assume that it's a time field, so if they come in at 10PM (22:00), and leave at 1AM (1:00), and you subtract, they will have been there for -21 hours!

Think about what technical support people ask when you contact them, but first, understand what you need and what you have:

Version of Crystal
Database used
Connectivity used
Example data (include relevent fields and their data types)
Expected output

In your case you now say that you need date fields, does the date field also contain a time? Many databases have both.

If not, what you need now is to build a datetime field in CR or on the database out of each date and time type, and then use a datediff in seconds, and then my FAQ gets you home.

Post the above and someone can resolve this quickly, it's standard stuff.

-k
 
Thank you "synapsevampire" for your help and for all the posts I will be more detailed now and in the future:

I just took a 4 day course from Crystalreports.com and we didn't cover this type of stuff. I am the only person at the hospital using this report writer and hoping to get to the point of publishing some basic reports

I am using Crystal Version 9
The Database is a home grown system on an as400 we are a small community hospital

I am using the emergency room log and doing 2 reports:
1 for promptcare which patients are all seen on the same day
2 for ER patients which can span over 2 days

The dates are broken out into month, day and year fields there is no CC. Data goes back to 1995 to present. One for admit one for discharge.

There are 2 time fields one for Admit time and one for discharge time.

What you wrote for me was perfect on formating the same day times. Now I must figure out how to do it when there are span dates.

The goal is to be able to see what is our high, low and average time a patient is in our ER vs Prompt care.

Thanks again for all your help.

The posting by VIDRU didn't work I recieved Date errors.

PS: I combined the dates with a silly litte formula since I am dealing with only 2000 data

DateValue(2000+{ERLOG.AYEAR},{ERLOG.AMONTH},{ERLOG.ADAY})

 
A datetime is constructed by using:

@admitdatetime
datetime(admityear,admitmonth,admitday,admithours,admitminutes,admitseconds)

Getting these from your fields, one for admit, one for discharge.

Once you have that it's easy to use a datediff function to return the difference in seconds:

datediff("s",admitdatetime,dischargedatetime)

Which will then suit my FAQ formula.

-k
 
One more question, I used the formula below and it works great. However, when trying to insert subtotals it will not allow me to average. Why? I need to be able to average the times?

Thanks

numberVar dur := datediff("s",{@admitdatetime},{@disch datetime}); //get the seconds between 2 dates
numberVar hrs;
numberVar min;
stringVar hhmmss;
hrs := Truncate(Truncate(dur/60)/60);
min := Remainder(Truncate(dur/60),60);
hhmmss := totext(hrs, "0") + ":" + totext(min, "00") ;

hhmmss
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top