Skip to content

Instantly share code, notes, and snippets.

@dgibson666
Last active November 18, 2016 15:06
Show Gist options
  • Save dgibson666/cfbf6b8ae3224072872aaffb814a3898 to your computer and use it in GitHub Desktop.
Save dgibson666/cfbf6b8ae3224072872aaffb814a3898 to your computer and use it in GitHub Desktop.
HTML5 Date Inputs
<input type="date" name="inspectionStart" value="#Dateformat(somedate,"yyyy-mm-dd")#">
<script>
$(document).ready(function () {
// If a browser doesn't support HTML5 date input types, then load a backup/polyfill
if(!Modernizr.inputtypes.date){
// Convert the format from the HTML5 dateformat of yyyy-mm-dd to mm/dd/yyyy
$('input[type=date]').each(function(){
var thisdate=$(this).val();
if(thisdate.length){
var dateparts=thisdate.split('-');
var newdate=dateparts[1]+'/'+dateparts[2]+'/'+dateparts[0];
$(this).val(newdate);
}
});
// Call the jQueryUI datepicker and use the same format as above
$('input[type=date]').datepicker({
//dateFormat: 'yy-mm-dd' // HTML5 format
dateFormat: 'mm/dd/yy'
});
}
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment