1 Reply Latest reply on Feb 22, 2012 10:35 AM by philmodjunk

    Subtract days/weeks/months from the timestamp?



      Subtract days/weeks/months from the timestamp?


      Hello everyone,


      I have two keyfields with seperate value lists. The first drop-down list is a set of numbers 1-50. The second list is set of terms : "hour(s), day(s), weeks(s), month(s), and year(s)." The combination of these two fields would be read as "2 hour(s)" or "21 year(s)"

      If at all possible, i would like to create a script that would subtract that result from the current date. So, if "2 days" was input, it would record 2/19/2012 (with today being 2/21/2012).

      Im fairly new to filemaker and have no idea how to begin to think about this. Any ideas?





        • 1. Re: Subtract days/weeks/months from the timestamp?

          Time stamps are really integer fields that store their data as seconds.

          Thus, hours * 3600 seconds/hour can be subtracted when hours are selected.

          Similar expressions can be used to subtract the equivalent seconds for days and weeks. And this can be done with a case statement that uses the specified units to apply the correct conversion.

          Months and Years are more a problem because each month and each year is not the same length (don't forget leap years).

          In those cases, you may want to use a different approach:

          Here's an example for subtracting months:

          Let ( [ TS = YourTimeStampField ; m = Month ( TS ) - YourNumberField ] ;
                   TimeStamp ( Date ( m ; Day ( TS ) ; Year ( TS ) ) ; Getastime ( TS ) )

          A similar expression can subtract years.