javascript - Add a number of days to a given date time -
i found various answers add no. of days given date. want add number of days date & time in format mm-dd-yyyy hh:mm:ss
i tried , successful when had date date & time returns invalid date when console.log(startdate)
html
<input type="text" id="startbidding" name="startbidding" > <input type="radio" name="expiry" value="5"> <span> 5 days </span> <input type="radio" name="expiry" value="10"> <span> 10 days </span> <input type="text" id="endbidding" name="endbidding" >
jquery
$(document).ready(function() { $('input[type=radio][name=expiry]').change(function() { var days = this.value; var startdate=new date($("#startbidding").val()); startdate.setdate(startdate.getdate()+parseint(days)); var inputdate = (startdate.getmonth()+1)+'-'+(startdate.getdate())+'-'+(startdate.getfullyear()); $("#endbidding").val(inputdate); }); });
you need put date format javascript parse correctly.
var new_date = $("#startbidding").val().replace( /(\d{2})-(\d{2})-(\d{4}) /, "$3-$1-$2t"); var startdate = new date(new_date);
fiddle: http://jsfiddle.net/wmsm0pnn/
Comments
Post a Comment