1 Reply Latest reply on Aug 27, 2010 3:21 AM by MrFork

    Getting Previous Period Date


      Hello - I'm wondering if anyone can help.


      Im currently developing a tool which filters and aggregates some data. I have the user to be able to select a period for example - 01/01/2010 to 07/10/2010.


      Then, I want to compare the selected data with the same period of the previous.


      I understand that I think I get do this with the .getTime function but Im at a loose end as to how to achieve this. Another example is if the user selects 2 years, e.g. 01/01/2010 - 01/01/2008 the comparison period would be 01/01/2006 - 01/01/2008


      Please help!






      public function filterAll(evt:Event):void
                      var tmpDate:Date = selectedFrom.selectedDate
                      var tmpDate2:Date = selectedTo.selectedDate
                      tmpDate.time = tmpDate.getTime();
                      tmpDate2.time = tmpDate2.getTime(); // this needs to be the previous period
                      trace (tmpDate)
                      trace (tmpDate2) // trace previous period


        • 1. Re: Getting Previous Period Date
          MrFork Level 1

          Think I've done it! Here is the function for anyone that is interested!


          public function getPreviousPeriod(From:Date,To:Date, fromOrTo:String):Date
                          var diffNum:Number = From.getTime() - To.getTime();
                          var tmpDate:Date = new Date
                          var tmpDate2:Date = new Date
                          tmpDate.time = From.getTime();
                          tmpDate2.time = To.getTime();
                          tmpDate.time = tmpDate.getTime() + diffNum
                          tmpDate2.time = tmpDate2.getTime() + diffNum
                          if (fromOrTo == "From")
                              trace ("FROM")
                              return tmpDate;
                              trace ("TO")
                              return tmpDate2;