html input date default today

Hello geeks! In this tutorial I have shared the details about “html input date default today”. Okay, let’s move on to the tutorial.

html input date default today

<!-- HTML -->
<input type="date" class="today">

<script>
  // JQuery
  $(document).ready( function() 
    $('.today').val(getToday());
  );
  
  function getToday()
	const local = new Date();
    local.setMinutes(local.getMinutes() - local.getTimezoneOffset());
	return local.toJSON().slice(0,10);
  
</script>
<!-- HTML -->
<input type="date" id="theDate">

<script>
  // JQuery
  $(document).ready( function() 
    $('#theDate').val(new Date().toDateInputValue());
  );
  
  // Pure JS
  document.getElementById('theDate').value = new Date().toDateInputValue();
  
  
  // Timezone support
  Date.prototype.toDateInputValue = (function() 
    var local = new Date(this);
    local.setMinutes(this.getMinutes() - this.getTimezoneOffset());
    return local.toJSON().slice(0,10);
  );
</script>

Final Words

I hope this tutorial helps you to know about “html input date default today”. If you have any questions regarding this tutorial please let us know via the comment section. Share this article with your friends and family via social networks.

Hi, I'm Ranjith a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coder Diksha. Here, I post about programming to help developers.

Share on:

Leave a Comment