2 Replies Latest reply on Sep 26, 2012 6:13 PM by LaRetta_1

    How to convert the Week No. back to a date?

    MaggieWu

      Title

      How to convert the Week No. back to a date?

      Post

           How to convert the Week No. back to a date?

           For example, I have the week no.=1 of the year 2012

           Any one know ehat formula or script can convertit back to a date like 01/01/2012?

            

           Thanks

           maggie

        • 1. Re: How to convert the Week No. back to a date?
          davidanders

               OS - Win or Mac - version?  FMP version?
               Field Name? Field Type (calculation?)?

               Normally, weekofyear is used with a calculation field to get the week number. This means that there had to have been a date field.

               If the date field exists, you have the information in the database.

          • 2. Re: How to convert the Week No. back to a date?
            LaRetta_1

                 Hi Maggie!!  Assuming the following:

                 You have a number field which holds the WeekOfYear number (let's call it numWks).  And you have a date field which can specify the year (otherwise change the bold portion in the calc to use a year number):

                 Let ( [
                 start = Date ( 1 ; 1 ; Year ( date ) ) ;
                 firstSun = start - DayOfWeek ( start )
                 ] ;
                 firstSun + 7 * numWks
                 )

                 ... will give you the last day of that week (Saturday), notice the -6 to back the date to the Sunday date.

                 Let ( [
                 start = Date ( 1 ; 1 ; globalYearField  ) ;
                 firstSun = start - DayOfWeek ( start )
                 ] ;
                 firstSun + 7 * numWks - 6
                 )

                 ... will give you the first day of that week (Sunday).  Use either the date to get the year or a year field (I provided both examples).

                 I had the -6 reversed and I've changed it.