The HTML5 input types are great, Opera\'s new built-in date picker is a breeze, and Chrome has at least supported the new input type with a spin-wheel implementation.
<<input type="date" id="aDate" name="aDate" class="form-control" value="{{ Date.now() | date("Y-m-d") }}" />
You could fill the default value through javascript as seen here: http://jsfiddle.net/7LXPq/
$(document).ready( function() {
var now = new Date();
var month = (now.getMonth() + 1);
var day = now.getDate();
if (month < 10)
month = "0" + month;
if (day < 10)
day = "0" + day;
var today = now.getFullYear() + '-' + month + '-' + day;
$('#datePicker').val(today);
});
I would probably put a bit of extra time to see if the month and date are single digits and prefix them with the extra zero...but this should give you an idea.
EDIT: Added check for the extra zero
Follow the standard Y-m-d format, if you are using PHP
<input type="date" value="<?php echo date("Y-m-d"); ?>">
if you need to fill input datetime you can use this:
<input type="datetime-local" name="datetime"
value="<?php echo date('Y-m-d').'T'.date('H:i'); ?>" />
This is very much simple by applying following code, Using PHP
<input type="date" value="<?= date('Y-m-d', time()); ?>" />
Date function will return current date, by taking date in time()
.
The following code works well:
<input type="date" value="<?php echo date('Y-m-d'); ?>" />
Note that this relies on PHP.