Jarvis Posted October 15, 2006 Posted October 15, 2006 I'm trying to write an application that captures start-stop times from data that is manually keyed into the database. In order to calculate elapsed time, I need to be able to control how the AM-PM part of the time is appended. FOR EXAMPLE: Is there a way to key in the value 7:15, select AM or PM from a value list and end up with a timestamp result of 7:15AM? My ultimate goal is to be able to subtract 7:15AM from 12:30PM to get the result 5.25 hours. Any ideas? Jarvis
CoZiMan Posted October 15, 2006 Posted October 15, 2006 (edited) The display fields don't have to equal the calc fields. This said you can create two time calc fields that are 24 hour based. Just generate the value of the start and end times with a plus 12 hrs based on the selection of the 'pm' entries. Now use a regular time calc field equal to stop - start and this gives you the elapsed time. So the list of fields for less than 24 hour tasks is: DISPLAY FIELDS: TimeStartHR TimeStartMIN TimeEndHR TimeStopMin TimeStartAmPm TimeEndAmPm CALC FIELDS: AmPmCalc = Case (TimeEndAmPm = (AM) and TimeStartAmPm (PM) ; 12 ; TimeEndAmPm = (AM) and TimeStartAmPm (AM) ; 0 ; TimeEndAmPm = (PM) and TimeStartAmPm (AM) ; 12 ; TimeEndAmPm = (PM) and TimeStartAmPm (PM) ; 0 ; 0) RealTimeStart = (GetasText(TimeStartHR) & ":" & GetasText(TimeStartMIN) RealTimeEnd = (GetasText(TimeEndHR + AmPmCalc) & ":" & GetasText(TimeEndMIN) RealElapsedTime = RealTimeEnd - RealTimeStart If you need to calc longer than this you need a day field for both entries and a test to calc that, more entries in the case statement, and then add to the RealTimeEnd. Simple? Not. Powerful? Yes Just remember that the display logic and values don't have to be the same as the cacl fields. Edited October 15, 2006 by Guest
Genx Posted October 15, 2006 Posted October 15, 2006 3 Fields: 1) Time Field -- Time (entered as 7:15, 9:20 etc.) 2) Text Field -- Suffix (i.e. AM or PM) 3) Calc Field result time -- Calc being Let(Tim = GetAsTime(TimeField) // The get as time isn't necessarily necessary -- though if you use a text field you'll have the same effect with this statement; If(Suffix = "AM" ; TIM ; TIM + (12 * 3600) ) )
comment Posted October 15, 2006 Posted October 15, 2006 How about something simple (and works in both directions)? timeEntry.fp7.zip
LaRetta Posted October 15, 2006 Posted October 15, 2006 I must be missing somethhing here ... FM does all of this itself on time fields. A global text to type 7:15 and another global text to select AM or PM (or simply type it as well) - will produce 7:15 AM in a time field. Same with the ending time. Then calculation (result is time) of End - Start will give you the overall time.
LaRetta Posted October 15, 2006 Posted October 15, 2006 (edited) Your post wasn't there when I started, Michael. Well since I did it, here's an example as well - how FileMaker knows the difference. You can just type AM/PM and it will keep track for you. I like Michael's idea ... but my vision of the request is a bit different so I'll attach my demo anyway. Both methods are very simple because FM does all the work. In this example, I mixed putting the time and AM/PM in separate globals but typing all directly into time works as well ... it depends upon what your Users see and need. Times.zip Edited October 15, 2006 by Guest
Jarvis Posted October 15, 2006 Author Posted October 15, 2006 Thanks guys (& guy-etts)! I will stare at your offerings and come to grips with this. Jarvis
Recommended Posts
This topic is 6958 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