Skip to content

Instantly share code, notes, and snippets.

@yuizho
Last active April 4, 2019 23:35
Show Gist options
  • Save yuizho/55c4d6fe52a21cdb739ac4938e63ac7f to your computer and use it in GitHub Desktop.
Save yuizho/55c4d6fe52a21cdb739ac4938e63ac7f to your computer and use it in GitHub Desktop.
input-date snippet
<input id="date-form" type="date" min="2019-04-01" max="2030-03-31">
<script>
(function() {
var dateForm = document.querySelector('#date-form');
var today = new Date();
var month = ('0' + (today.getMonth() + 1)).slice(-2);
var day = ('0' + today.getDate()).slice(-2);
// set today as default value
dateForm.value = `${today.getFullYear()}-${month}-${day}`
}())
</script>u
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment