Search code examples
apache-flexdateadddatefield

flex builder 3 : how to create automatically dateadd day/month/year process in datefield


i was trying to create automatically add day but result still math calculation not date calculation. example if you create +14 and you choose date 20-11-2016 the result should be 04-12-2016 but my function result still math calculation and result 34-11-2016. thanks for your help.sorry bad english

private function useDate(df_start:CalendarLayoutChangeEvent):void {
        // Make sure selectedDate is not null.
        if (df_start.currentTarget.selectedDate == null) {
            return 
        }

        //Access the Date object from the event object.         
        df_target.text=df_start.currentTarget.selectedDate.getFullYear() +'-'+
                        (df_start.currentTarget.selectedDate.getMonth()+ 1) +'-'+
                       (df_start.currentTarget.selectedDate.getDate() + 14);

    }

Solution

  • When you are using getDate() method, it is only returning the Number and thats why you are getting numerical operation. Use the Date.date method to set date as below.

            private function useDate(df_start:CalendarLayoutChangeEvent):void {
            // Make sure selectedDate is not null.
            if (df_start.currentTarget.selectedDate == null) {
                return 
            }
    
            var date1:Date = df_start.currentTarget.selectedDate;
            date1.date +=14;
    
            //Access the Date object from the event object.         
            df_target.text=date1.getFullYear() +'-'+
                       date1.getMonth() +'-'+
                       date1.getDate();
    
    }