Created
November 6, 2019 16:10
-
-
Save Danushka96/3912d997c493c204de5abf66222489a0 to your computer and use it in GitHub Desktop.
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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<meta http-equiv="X-UA-Compatible" content="ie=edge"> | |
<title>Document</title> | |
</head> | |
<body> | |
<input type="date" id="inDate"><br><br> | |
<input type="date" id="outDate"> | |
<div id="output"></div> | |
<script type="text/javascript"> | |
Date.prototype.addDays = function(d) { | |
this.setDate(this.getDate() + d); | |
return this; | |
}; | |
var inputDate = document.getElementById('inDate'); | |
var outDate = document.getElementById('outDate'); | |
var inDateValue = inputDate.value; | |
inputDate.onchange = function(event) { | |
var d = new Date(this.value) | |
var dd = d.getDate(); | |
var mm = d.getMonth() + 2; //January is 0! | |
var yyyy = d.getFullYear(); | |
var newDate = yyyy + '-' + mm + '-' + dd; | |
outDate.value = newDate; | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment