ExpressVP Posted April 9, 2007 Posted April 9, 2007 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.
Genx Posted April 9, 2007 Posted April 9, 2007 Time doesn't seem to want to subtract directly... (GetAsNumber(arrivalTime) - GetAsNumber(departureTime)) / 3600 Or just GetAsNumber(arrivalTime - departureTime) / 3600
comment Posted April 9, 2007 Posted April 9, 2007 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.
Genx Posted April 9, 2007 Posted April 9, 2007 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?
Genx Posted April 10, 2007 Posted April 10, 2007 I don't know i'm too confused to think about this right now.
ExpressVP Posted April 10, 2007 Author Posted April 10, 2007 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.
LaRetta Posted April 10, 2007 Posted April 10, 2007 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.
comment Posted April 10, 2007 Posted April 10, 2007 This thread seems to be afflicted with things that "seem not to work". timeDiff.fp7.zip
Recommended Posts
This topic is 6498 days old. Please don't post here. Open a new topic instead.
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now