3 Replies Latest reply on Jun 21, 2012 6:30 AM by philmodjunk

    Working with dates



      Working with dates




      I need to do some stuff to a date in a script, and I can't quite figure out how to do certain things:

      First of all, I have a date. (it's either Get (CurrentDate) or it comes as a script parameter) The script assumes that this is the first work day of a new month, (next one would be July 2nd) finds all the orders for the last two months, sucks data out of them and feed them into a report.

      So what I need to do is somehow get the values for the last two months from this date. In case of July 2nd, I need $month1 value to be 2012/05/01 or just 2012/05 (May 2012) and $month2 to be 2012/06/01 (or 2012/06)


      Second thing I need to do, is search for values that correspond to that one month. I know how to search within a date range, ( $date1 .. $date2) but how do I say "find me records that have date somewhere in April 2012"

        • 1. Re: Working with dates

          For the second find you just search for 4-2012. Or just 4 if you only have one year.

          You could do:

          Month (Get (CurrentDate) ) -2 & "-" & Year (Get (CurrentDate))

          To find the records for the entire month 2 months ago.

          Also, look here:


          It's quite interesting.

          • 2. Re: Working with dates

            How can you calculate dates to the day, but display them in years?

            I just want to display how old they are in years, but only if they have reached the age in question.

            If I have a calculation using “Year ( Get ( CurrentDate ) )” and “Year ( ChildDateofbirth )”, FMP calculates whole years. That is, it’s June now and for a child born in say, September 2010, they are shown as 2 years old – but they’re not yet.

            • 3. Re: Working with dates

              To display the contents of a date field in different formats, use the data formatting found on the Inspector's data tab. You can format a date field so that just the month, the month and year or just the year is displayed.

              To compute a person's age using the current date and their birth date would be done in an unstored calculation field with this expression:

              Let ( T = Get ( CurrentDate ) ; Year ( T ) - Year ( DateOfBirth ) - ( Date ( Month ( DateOfBirth ) ; Day ( DateOfBirth ) ; Year ( T ) ) > T ) )

              This subtracts 1 if this year's birthday is greater than today's date.