Jump to content

time conversion calc question


This topic is 5711 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Hello

I have some events which take place in either of the following fields [color:orange]Years, [color:orange][color:orange]days, [color:orange]hours, [color:orange]minutes, [color:orange]seconds. I would like to always convert the times to lowest denominator or seconds. It seems easy to me until i have something that takes place for example like

5 years, 34 days, 13 hours, 41, minutes and 12 seconds.

I don't know how to write the script. I can do it if it is just one element like years but I don't know how to add them together. Or to account for those fields which have nothing in them in the calculation.

I have the same problem with a distance calc ( where there will be [color:orange]miles, [color:orange]feet, [color:orange]inches . The first answer should answer my second problem. I just don't know how to make a calculation that works for every situation or a couple of them like days and hours by themselves.

Link to comment
Share on other sites



Let(

years = Field_Years;

days = Field_Days;

hours = Field_Hours;

minutes = Field_Minutes;

seconds = Field_Seconds];



seconds + (minutes * 60) + (hours * 3600) + (days * 86400) + (years *  315360000))



This isn't exactly neat, and I'm sure there are easier ways to do it, but that would get you the number of seconds. Be careful though, filemaker does things with large numbers, and I highly doubt you'll actuall see a number, you'll likely see a truncated number.

Anyhow, you can do the same thing with distance, and blank fields won't matter as you multiply them, they will return 0.

Again, my solution will always give you seconds.

Edited by Guest
Link to comment
Share on other sites

I have the same problem with a distance calc ( where there will be miles, feet, inches . The first answer should answer my second problem.

Not really - there's a difference. One feet is always 12 inches, and one mile is always 5,280 feet (63,360 inches). But a year can have either 365 or 366 days, so you cannot translate accurately from years to days (and subsequently to seconds).

Link to comment
Share on other sites

A few quick comments since this is one of my favorite subjects...

1) The purpose of Let() is to insert variables which can perform (or does perform) a function once (or many times - against itself or its result) to save evaluations/steps OR to simply add clarity. But in this case, the fields themselves ARE clear (Years, Seconds, Minutes, Hours and Days) and it seems unnecessary.

2) Wrapping with the extra parenthesis is not required - multiply/divide comes BEFORE add/subtract (unless parentheses dictate otherwise). And days should be * 86400 not + ... small typo, I'm sure. But, since we are dealing with large numbers, the error may NOT be noticed so I thought I should mention it. So the calc could be simply:

Seconds + Minutes * 60 + Hours * 3600 + Days * 86400 + Years * 315360000

But a year can have either 365 or 366 days, so you cannot translate accurately from years to days (and subsequently to seconds).

Yes - unless you have DATE and TIME spans. So two records, both with 36 years can't truly be compared down to seconds anyway because each record may come from a different year. So, since your comparison is NOT accurate down to the seconds, why deal with it? Why not convert at least to minutes so it is readable as:

Div ( Seconds + Minutes * 60 + Hours * 3600 + Days * 86400 + Years * 315360000 ; 60 )

This will eliminate the scientific notation unless you're up over 190 years or so. Fascinating stuff indeed!! :wink2:

LaRetta

Link to comment
Share on other sites

I used the let statment because I wasn't sure how he had things set up, if it is just a field, LaRetta's right, there is no need for it.

And I forgot all about leap years, although adding an extra day wouldn't be that hard, if you just added one every 4 years. However, now that I think about it, there is no real way (other than above) to know if a leap year happened or not, at least not the way he defined having his data.

Thanks to LaRetta for catching my typo, that could have seriouly confused someone, i'll fix it now.

Link to comment
Share on other sites

I forgot all about leap years, although adding an extra day wouldn't be that hard, if you just added one every 4 years

No, it wouldn't be hard. But would it be correct?

Say an event lasted 5 years. Out of those 5 years, how many were leap years? It could be 1, it could be 2, and it could be 0. There's no way tell, unless you know WHICH years those 5 years were.

Link to comment
Share on other sites

However, now that I think about it, there is no real way (other than above) to know if a leap year happened or not, at least not the way he defined having his data.

Thats what I meant here comment, shoot, we don't even know if it was 5 years, 20 days, 12 minutes... in a row, it could be an accumilated time.

Link to comment
Share on other sites

This topic is 5711 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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

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