0

I want to impliment the same functionality as in this qeustion JQuery ui - date picker, disabling specific dates , the script working fine(see the code below), but the problem is I am getting Unavailable dates from database, so the dates has a leading zero, ie var unavailableDates = ["90-3-2012", "14-03-2012", "15-03-2012"]; If I test with same dates without leading zero it works, but I want to with leading zero.

How can we format the dates, I am using the exact code from an answer for the above said quesiton , here is the code

<script type="text/javascript"> var unavailableDates = ["9-3-2012", "14-3-2012", "15-3-2012"]; function unavailable(date) { dmy = date.getDate() + "-" + (date.getMonth() + 1) + "-" + date.getFullYear(); if ($.inArray(dmy, unavailableDates) == -1) { return [true, ""]; } else { return [false, "", "Unavailable"]; } } $(function() { $("#iDate").datepicker({ dateFormat: 'dd MM yy', beforeShowDay: unavailable }); }); </script> 

1 Answer 1

3

You can use datepicker to format date like

var unavailableDates = ["09-03-2012", "14-03-2012", "15-03-2012", "15-07-2015"]; function unavailable(date) { var dmy = $.datepicker.formatDate('dd-mm-yy', date); console.log(dmy) if ($.inArray(dmy, unavailableDates) == -1) { return [true, ""]; } else { return [false, "", "Unavailable"]; } } $(function() { $("#iDate").datepicker({ dateFormat: 'dd MM yy', beforeShowDay: unavailable }); });
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.js"></script> <link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/redmond/jquery-ui.css" /> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.js"></script> <input id="iDate" />

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.