I have set an input to be a date picker using datepicker()
on document ready and I have set the format to be dd-mm-yy
.
When the input is changed I get the value of the input with Date()
.
My issue is that Date()
is expecting a format of mm-dd-yy
so when I use getDay()
test to see which day it is, it returns the wrong value.
How can I make this code work using the dd-mm-yy
format?
jQuery(document).ready(function($){
if( $('#booking_form').length ){
$('#date input')
.prop('readonly', true)
.datepicker({ dateFormat: 'dd-mm-yy' });
}
$('#date input').change(function(){
date_function();
});
function date_function(){
//getting the date
var date = new Date( $('#date input').val() );
if( date.getDay() === 0 || date.getDay() === 1 ){
$('#custom_error').show();
} else {
$('#custom_error').hide();
}
}
});