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!

Time Difference Formula 1

Status
Not open for further replies.

mbumstead

Technical User
Apr 30, 2009
13
US
The formula below is a formula that calculates the time difference and it includes after midnight formula so we can report on how long a surgery was. The problem with the formula is that if the time difference is under 60 min. I get a 0 for the time difference. Do you have any suggestions as to how I can make this formula work? Or is there another one out there that is better?
Thanks.

If {v_CRA_or_pt_time_group.pt_time_outroom}>{v_CRA_or_pt_time_group.or_time_close}
Then ((Truncate({v_CRA_or_pt_time_group.pt_time_outroom}/100)*60)+
(ToNumber(Right(ToText({v_CRA_or_pt_time_group.pt_time_outroom}/100),2))))-
((Truncate({v_CRA_or_pt_time_group.or_time_close}/100)*60)+
(ToNumber(Right(ToText({v_CRA_or_pt_time_group.or_time_close}/100),2))))
ELSE
(1440-(Truncate({v_CRA_or_pt_time_group.or_time_close}/100)*60+
ToNumber(Right(ToText(({v_CRA_or_pt_time_group.or_time_close}/100)),2))))+
(Truncate({v_CRA_or_pt_time_group.pt_time_outroom}/100)*60+
ToNumber(Right(ToText(({v_CRA_or_pt_time_group.pt_time_outroom}/100)),2)))
 
Which version of Crystal are you using? Anything past 7 and you will be able to use the Datediff function

datediff("n",{v_CRA_or_pt_time_group.or_time_close},{v_CRA_or_pt_time_group.pt_time_outroom})

will return the number of minutes, the are other flags for hours or seconds.
 
I am using Crystal XI. This will also calculate the cases that start before midnight and end after midnight correctly?
 
I have also used the below formula but it will not calculate the time difference if it is after midnight

DATEDIFF("n",



DateTime ( DATE({v_basic_case_rec_data.cr_prdate}),

Time ( TONUMBER(TOTEXT({v_CRA_or_pt_time_group.pt_time_inroom},"0000")[1 to 2]),

TONUMBER(TOTEXT({v_CRA_or_pt_time_group.pt_time_inroom},"0000")[3 to 4]),

00) )

,



DateTime ( DATE({v_basic_case_rec_data.cr_prdate}),

Time ( TONUMBER(TOTEXT({v_CRA_or_pt_time_group.pt_time_outroom},"0000")[1 to 2]),

TONUMBER(TOTEXT({v_CRA_or_pt_time_group.pt_time_outroom},"0000")[3 to 4]),

00) )

)

 
I think that is because in your example {v_basic_case_rec_data.cr_prdate} will be the same day. it looks like you are calculating the end time appearing before the start time.

You need the 2nd datetime to have a field that shows the case ended the next day ({v_CRA_or_pt_time_group.pt_date_outroom} ? ). It must exist in the program.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top