-1

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);

    }
Ihsan Dn
  • 31
  • 8

1 Answers1

0

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();

}
Sumit
  • 729
  • 4
  • 9
  • this function still have a problem in month. you know that getMonth in flex need +1 and how to +1 for month? i was trying to create new var with +1 but not working. thanks for help by the way. – Ihsan Dn Dec 20 '16 at 09:00
  • For getMonth you can do date1.getMonth() + 1. That is ok as month starts from 0 in actionscript. df_target.text=date1.getFullYear() +'-'+ (df_start.currentTarget.selectedDate.getMonth()+ 1) +'-'+ date1.getDate(); – Sumit Dec 20 '16 at 11:26