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!

Formula for calculating DateTime intervals 1

Status
Not open for further replies.

madsstiig

Technical User
Jun 11, 2008
50
DK
Hi.
I'm trying to create a report that shows the time certain patients have to wait for an examination.
I tried to use:

local numbervar T;
global timevar F;
global timevar D;
if {RISLOG.LTRANS} = 'Ny status: Besk.afs' then D := time ({RISLOG.LDATETIME});
if {RISLOG.LTRANS} = 'Dokumentation' then F := time ({RISLOG.LDATETIME});
T:= (D-F)/60;
T;

where {RISLOG.LDATETIME} is my DateTime field in format (dd-mm-yyyy hh:mm:ss) but this formula doesn't account for different dates and thus comes with a result as if the time interval is within the same 24 hours.
How do I make the date count as well?
Best regards Mads, Copenhagen - Denmark
 
You don't say what version you're using, but take a look at datediff in the formula help text. If it's not there, could be time to upgrade?

Datediff takes 3 parameters - 2 dates and an interval type. You can have intervals of pretty much anything - minutes, hours, days, weeks, months etc.

Andrew Baines
 
Try creating two different formulas like this:

//{@stat1}:
if {RISLOG.LTRANS} = 'Ny status: Besk.afs' then
{RISLOG.LDATETIME}

//{@stat2}:
if {RISLOG.LTRANS} = 'Dokumentation' then
{RISLOG.LDATETIME}

Then in the patient group header or group footer, use a formula like this:

datediff("s",maximum({@stat1},{table.patientID}), maximum({@stat2},{table.patientID}))

..with the most recent datetime in the {@stat2} position --not sure which one is appropriate. This also assumes there is only one of each type of status per patient.

-LB
 
Hi guys. I've been fiddling a bit with this not being able to finish the report (luckily it's not all I do, hehe).
I've found another obstacle:
I need to subtract a DateTime field from a Time field.
How do I do that. Can I make CR ignore the 'Date part' of the field or ... what to do here?
Best regards :)
 
Turn the time into a datetime with the same date as the datetime.
If your fields are {myTime} and {myDateTime}:

datetime(date({myDateTime}), {myTime})

Then use datediff to find the difference as earlier.
When you use datediff, careful what difference you use - if you ask for hours, you will get a whole number of hours, ie 30 minutes is 0 hours, not 0.5


Andrew Baines
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top