locked
How to Add months in Datepicker on textbox using jquery RRS feed

  • Question

  • User-712926555 posted

    Hi,

    I have dateTime in the format of Tue Feb 23 2016 00:00:00 GMT+0530 (India Standard Time)

    How add 2 months from this format

    function GetToDate() {
           var fromDate = $('#<%=txtFromDate.ClientID %>').val();   //In the format of dd-mm-yy (23-02-2016)
    
           var spliter = fromDate.split("-");
           var ConvertDate = new Date(spliter[2] + "-" + spliter[1] + "-" + spliter[0]); //Tue Feb 23 2016 00:00:00 GMT+0530 (India Standard Time)
    
           var toDate = ConvertDate.setDate(ConvertDate.getMonth() + 2);
    
           $('#<%=txtToDate.ClientID %>').val(toDate);
    }

    It return value like 14569632000000. What is wrong in it? Help me

    Tuesday, February 23, 2016 7:25 AM

Answers

  • User632428103 posted

    Hello hisanth,

    try this :

      var newMonth  = ConvertDate.getMonth() + 2; // => + 2 => add just one month => based on index = 0 => if you want add two month add 3 and so on ...
    
                var toDate = ConvertDate.getDate() + "-" + newMonth + "-" + ConvertDate.getFullYear();

    hope this help

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, February 23, 2016 8:57 AM
  • User61956409 posted

    Hi Hisanth,

    You could try to pass “fromDate” as parameter to web method and call AddMonths method to get new date and in AJAX success callback function you set returned date as the value of “txtToDate”.

    Best Regards,

    Fei Han

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, February 24, 2016 6:21 AM

All replies

  • User632428103 posted

    Hello hisanth,

    try this :

      var newMonth  = ConvertDate.getMonth() + 2; // => + 2 => add just one month => based on index = 0 => if you want add two month add 3 and so on ...
    
                var toDate = ConvertDate.getDate() + "-" + newMonth + "-" + ConvertDate.getFullYear();

    hope this help

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, February 23, 2016 8:57 AM
  • User61956409 posted

    Hi Hisanth,

    You could try to pass “fromDate” as parameter to web method and call AddMonths method to get new date and in AJAX success callback function you set returned date as the value of “txtToDate”.

    Best Regards,

    Fei Han

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, February 24, 2016 6:21 AM