April 9, 200718 yr I would like to define a new field, that would subtract two different times, and give me the difference. I have field A, the arrival time, and field B, the departure time. I want to have C show how many hours are in between them. All my events last less than a day. The problem I'm having is that Field A and Field B, are in Time format. Field C, is a calculation that has (Field - (Field A). What I want is for field C to give me the difference, but what it's doing is it's giving me a negative number because it's going back a whole day from AM to PM. Can anyone give me a tip on what to change? Thanks.
April 9, 200718 yr Time doesn't seem to want to subtract directly... (GetAsNumber(arrivalTime) - GetAsNumber(departureTime)) / 3600 Or just GetAsNumber(arrivalTime - departureTime) / 3600
April 9, 200718 yr Time doesn't seem to want to subtract directly... Since when? A simple Arrival - Departure works fine for me. I suspect the problem is with events crossing midnight, which can be handled by: Arrival - Departure + 86400 * ( Departure > Arrival ) You can leave the result as Time, and format the display to your liking, or - if you want decimal hours - make it a Number and divide by 3600.
April 9, 200718 yr Don't know, didn't seem to work for me... kept giving me much larger neg values i.e. 1pm - 11am = -22 (i don't remember if that's actually what it spat out, but it was much larger than it should have been). Don't know, seems to work now, and you're probably right re the midnight thing -- but why does it make the assumption?
April 10, 200718 yr Author Since when? A simple Arrival - Departure works fine for me. I suspect the problem is with events crossing midnight, which can be handled by: Arrival - Departure + 86400 * ( Departure > Arrival ) You can leave the result as Time, and format the display to your liking, or - if you want decimal hours - make it a Number and divide by 3600. That is exactly the problem I'm having. For events crossing midnight, it's counting backwards, or adding 12 to it and giving me a negative result. I tried your method and it still seems to be doing that.
April 10, 200718 yr It works perfectly for me. Departure 1:00 PM (or even 1 PM) Arrival 11:00 AM (or even 11 AM) Calculation (result is time) = Arrival - Departure + 86400 * ( Departure > Arrival ) Result: 22 hours or 22:00:00 Nothing I do can make it run negative or break. Are you sure all three fields are time? And are you sure you don't have Arrival and Departure reversed? That's what it sounds like you're doing. But even so, Comment's calculation would not break.
April 10, 200718 yr This thread seems to be afflicted with things that "seem not to work". timeDiff.fp7.zip
Create an account or sign in to comment