Reputation: 1618
I have a form field which is using datepicker.
The form field is has a value applied via php in the format yymmdd
<input type='text' id='date' name='date' value='<?php echo $date ?>'>
JQuery:
$("body").on('focus', '#date', function(){
$( this ).datepicker({ dateFormat: "d MM yy", minDate: 0, maxDate: "+1Y -1D"});
});
When the page loads the value appears in the field eg: 160914
What I'd like to do is have datepicker detect this format correctly, so when the picker appears the 14th September 2016 is highlighted.
I'd also like when the user selects a date, the field would show eg: 21 September 2016, but the value available to be written back to the database would be 160921
Can this be done ? Can someone point me in the right direction ?
Thanks
Upvotes: 0
Views: 92
Reputation: 424
I think i found solution for you. Just to note that your dateFormat was wrong. Check documentation for all details. However :) Maybe is good idea to print better date with Php, some useful format like Y-m-d. Check that and good luck:
$('input').datepicker({ altFormat: "y mm d", dateFormat: "dd MM yy", minDate: 0, maxDate: "+1Y -1D"});
$('input').val($.datepicker.formatDate("dd MM yy", $('input').datepicker("getDate")));
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.0/jquery-ui.min.js"></script>
<input type='text' id='date' name='date' value='16 09 14'>
Upvotes: 1