Jump to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Custom Function Calc

Featured Replies

I have a custom function calculating Elapsed Time from when an email comes in to the database. heres the function:

Let (

[

seconds = If( IsEmpty(tsEnd) ; "" ; tsEnd- tsStart) ;

minutes = seconds/60 ;

hours = minutes/60 ;

days = hours/24;

months = days/30;

years = months/12;

displaySeconds = Mod(seconds ; 60);

displayMinutes = Int(Mod(minutes; 60));

displayHours = Int(Mod(hours ; 24));

displayDays = Int(Mod(days; 30));

displayMonths = Int(Mod(months; 12));

displayYears = Int(Div(months; 12))

];

Case(

IsEmpty(tsEnd); "" ;

displayDays & "d " & displayHours & "h " & displayMinutes & "mins"

) // end Case

) // end Let

when an emails age is under an hour, is displays as follows:

"0d 0h 23mins"

I would like it to display as "23mins"

When an emails age is over an hour but under one day it displays:

"0d 4hr 32mins"

i would like it to be displayed as "4hrs 32mins"

The below Case statement controls the output:

Case(

IsEmpty(tsEnd); "" ;

displayDays & "d " & displayHours & "h " & displayMinutes & "mins"

) // end Case

i need to figure out the calculation or statement to enter here so that:

1. IF days = 0 then "(displayHours & "h " & displayMinutes & "mins")"

elapsedtime.zip

I attempted to download your file, and it failed to decompress.

Here is a Custom Function that might help you. Link, if not, look around Brian Dunning's site as there are others.

BTW, you don't reflect that you have the Developer or Advance Edition of FileMaker in your profile, If you are using one of these, you need to update your Profile.

Lee

  • Author

SOrry, just updated my info as i see it can be useful. Here is another try at uploading my sample data, i got the custom function from that same website, the problem is the one you sent me does not tell me the number of minutes.

I dont know why my zip files are corrupt, but what below are two files, please download the larger of the two and rename the file from .zip to .fp7

its not compressed, i just changed the extension so that the server at fmforum allows me to upload it without becoming corrupt

elapsedtime.zip

elapsedtime.zip

Edited by Guest

its not compressed, i just changed the extension

Please don't do that.

As for your calculation, try:


Let ( [

e = tsEnd- tsStart ;

d = Div ( e ; 86400 ) ;

r = Mod ( e ; 86400 )

] ;

Case ( not IsEmpty ( tsEnd ) ; 

Case ( d ; d & "d " ) & Hour ( r ) & "h " & Minute ( r ) & "mins "

)

)

You should remove all of your attachments.

You have to actually Zip the files, or they do NOT come through so that we can open them.

These two files acted the same as your first file. i.e. they do not open. Zipping a file does not corrupt them it.

Lee

Edited by Guest

  • Author

thanks, that is perfect. i was trying to understand the function but didnt quite get it. i was trying to figure out how i could get rid of the 0h so that anything under an hour only displays the mins. this is not important but would be nice to have

thanks in advanced,

Just do the same thing for the hours as for the days - put them inside a Case() statement. But what do you want as the result when hours = 0 but days > 0?

  • Author

thanks im going to try what you just mentioned

as far as your follow-up question:

0days = Xhrs Xmins

0days 0hrs = Xmins

The question was about 2days 0hrs 25mins. Do you want the hours to show in such case?

  • Author

i dont want anything with a zero, so that would be 2days 25mins

Well, then:


Let ( [

e = tsEnd- tsStart ;

d = Div ( e ; 86400 ) ;

r = Mod ( e ; 86400 ) ;

h = Hour ( r ) ;

m = Minute ( r )

] ;

Case ( tsEnd ; 

Case ( d ; d & "d " ) & 

Case ( h ; h & "h " ) &

Case ( m ; m & "mins " )

)

)

Create an account or sign in to comment

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.