7 Replies Latest reply on Dec 5, 2016 10:20 AM by erolst

# Time unit calculation

Hi all

need help in calculating time unit have field start time and end time, every 15 minutes interval for the first hour is 2 units and after 1 hour is 3 units ( still 15 minutes) should bring number not decimal i.e 16 minutes should be 2

thanks

Hi,

• ###### 2. Re: Time unit calculation

hi david

basically i have 5 fields

1. start time

2. end time

3. time unit calculation

4. rate per unit

5 total amount

what i need filemaker to do is on calculation field time unit to be number (not decimal)

every 15 minutes is 2 units for the first hour and 3 units for every 15 minutes after first hour

my answers(s) will be like this

14 minutes =2

17 minutes= 4

62 minutes= 11 (8 FOR THE FIRST HOUR AND 3 FOR 15 MINUTES AFTER 1 HOUR

THANKS@David

• ###### 3. Re: Time unit calculation

Try

Let  ( [

t = GetAsNumber ( endTime - startTime ) ;

afterOne = Max ( 0 ; t - 3600 ) ;

beforeOne = t - afterOne

] ;

Ceiling ( beforeOne / 900 ) * 2 + Ceiling ( afterOne / 900 ) * 4

)

• ###### 4. Re: Time unit calculation

Let(

[

start = Main::timestamp1;

end = Main::timestamp2;

quarters = Ceiling ( (end - start) / 900 );  // 900 = 15min * 60sec

overFour = quarters - 4

];

Case(

overFour > 0; overFour * 3 + 8;  // 8 = 2 units * 4 quarters

quarters > 0; quarters * 2;

-1  // error

)

)

• ###### 5. Re: Time unit calculation

David Moyer wrote:

since I had already worked on this, here's another version ... [...]

I like your beginning better, but prefer my end; so let's combine the two:

Let ( [

t = GetAsNumber ( end - begin ) ;

q = Ceiling ( t / 900 ) ;

over = Max ( 0 ; q - 4 ) ;

under = q - over

] ;

under * 2 + over * 4

)

1 of 1 people found this helpful
• ###### 6. Re: Time unit calculation

that works too - except you typed too fast - should be "over * 3".

• ###### 7. Re: Time unit calculation

Exactly.

David Moyer wrote:

that works too

Well, I think it is "jus-telegant", as Marilyn once said (not to me, though ).