Shahmee Shahmee - 5 months ago 16
Javascript Question

Increase one month using jQuery

I have two date input field. I need to increase one month and set that value to second input field. This what I tried, used DD/MM/YYYY date format.

var f= new Date($(#firstDate).val());
f.setMonth( f.getMonth( ) + 1 );
seconddate = ( f.getMonth( ) + 1 ) + '/' + f.getDate( ) + '/' + f.getFullYear( );
$(#secondDate).val(seconddate);


This is the results i'm getting in console.

var f= new Date(19/06/2016);
f.setMonth( f.getMonth( ) + 1 );
seconddate = ( f.getMonth( ) + 1 ) + '/' + f.getDate( ) + '/' + f.getFullYear( );
"2/1/1970"

Answer

You have a problem, you try to insert in the new date() this format dd/mm/yyyy, new date only accepty dates in this order (year, month, day, hours, minutes, seconds, milliseconds)