Search code examples
apache-flexdaterangeenumerate

Enumerate days between two dates - Flex AS3


Does Flex dateChooser have any capabilities to enumerate dates for a given range? Say Start date is 2013-12-25 and end date is 2014-03-15. How can I print:

2013-12-25
2013-12-26
2013-12-27
...
2013-12-31
2014-01-01
2014-01-02
...
2014-03-15 

Thanks :)


Solution

  • It doesn't, but this is something you could do by creating your own function easily:

    protected function getDatesBetween(start:Date,end:Date):Array{
      var dates:Array = [start];
      const DAY_TO_MS:Number = 24*60*60*1000;
    
      var next:Date = new Date( start.getTime() + DAY_TO_MS );
      while( next.getTime() < end.getTime() ){
        dates.push( next );
        next = new Date( next.getTime() + DAY_TO_MS );
      }     
      dates.push( end );
    
      return dates;
    }