Written by me@grafxflow
06 Dec, 2012
2
5,442
Here is a nifty little script for disabling dates, if you are using the jQuery datepicker.
One thing to remember all the days and months must be a single digit so the 1st of February 2012 should be 1-2-2012 NOT 01-02-2012
<script type="text/javascript">
$(document).ready(function(){
var unavailableDates = ["26-12-2012","27-12-2012","28-12-2012","29-12-2012","30-12-2012","31-12-2012","1-1-2013","2-1-2013","3-1-2013","4-1-2013","5-1-2013","6-1-2013"];
function unavailable(date) {
dmy = date.getDate() + "-" + (date.getMonth() + 1) + "-" + date.getFullYear();
if ($.inArray(dmy, unavailableDates) == -1) {
return [true, ""];
} else {
return [false, "", "Not Available"];
}
}
$('#date_output').datepicker({ beforeShowDay: unavailable, dateFormat: 'dd-mm-yy', changeFirstDay: false, firstDay: 1, minDate: 0, onSelect: function(dateStr) {
}});
});
</script>
If you also want to be able to output the date range using php then this should help.
<?php
function dateRange( $first, $last, $step = '+1 day', $format = 'j-n-Y' ) {
$dates = array();
$current = strtotime( $first );
$last = strtotime( $last );
while( $current <= $last ) {
$dates[] = date( $format, $current );
$current = strtotime( $step, $current );
}
return $dates;
}
// Example usage
print_r( dateRange( '2010/07/26', '2010/08/05') );
?>
24 Nov, 2013
07 Nov, 2012
26 Apr, 2018
I am a Full-stack Developer who also started delving into the world of UX/UI Design a few years back. I blog and tweet to hopefully share a little bit of knowledge that can help others around the web. Thanks for stopping by!
Follow11 Jul, 2023
21 Jun, 2023
Views: 166,586
Views: 40,466
Views: 37,234
Views: 33,736
2 Response
genasky
21 Dec 2018
how to disable date from my database using php
me@grafxflow
28 Dec 2018
Hi Genasky,
Unsure if I know exactly what you mean.
Could you go into more detail?