No DateAdd()…?

Either I’ve missed something, or there is no DateAdd() function built into the basic Flex installation. Well that simply won’t do, I need to be able to add dates! There’s no DateDiff(), either. I must be missing something.

private function DateAdd(origDate:Date, addVal:int, addUnit:String):Date{
  var newDate:Date;
  switch(addUnit){
    case 'y':
      newDate = new Date(origDate.fullYear+addVal, origDate.month, origDate.date);
      break;
    case 'm':
      newDate = new Date(origDate.fullYear, origDate.month+addVal, origDate.date);
      break;
    case 'd':
      newDate = new Date(origDate.fullYear, origDate.month, origDate.date+addVal);
      break;
  }
  return newDate;
}

~ by codingmurloc on May 11, 2007.

Leave a Reply

You must be logged in to post a comment.