Created
November 8, 2022 08:03
-
-
Save codeeshop-oc/638ae33a6d081c4f52640b832721bd03 to your computer and use it in GitHub Desktop.
Set Start and End Date Based on Number of days
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let getDateInFormat = function (dated) { | |
let dd = String(dated.getDate()).padStart(2, '0'); | |
let mm = String(dated.getMonth() + 1).padStart(2, '0'); //January is 0! | |
let yyyy = dated.getFullYear(); | |
return dated = yyyy + '-' + mm + '-' + dd; | |
} | |
let addDays = function (date, addDays) { | |
return date.setDate(date.getDate() + parseInt(addDays)); | |
} | |
let setDates = function () { | |
if(new Date($('#startDate').val()) == 'Invalid Date') { | |
let startdate = getDateInFormat(new Date()) | |
$('#startDate').val(startdate) | |
let enddate = new Date(addDays(new Date(), $('#no_of_days').val())) | |
$('#endDate').val(getDateInFormat(enddate)) | |
} else if($('#startDate').val()) { | |
let enddate = new Date(addDays(new Date($('#startDate').val()), $('#no_of_days').val())) | |
$('#endDate').val(getDateInFormat(enddate)) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment