Peter Stuart
Peter Stuart

Reputation: 2434

How do I restrict dates on datepicker after a certain time?

At the moment I have this code here:

<script type="text/javascript" src="catalog/view/javascript/jquery/ui/jquery-ui-timepicker-addon.js"></script> 
<script type="text/javascript"><!--
if ($.browser.msie && $.browser.version == 6) {
    $('.date, .datetime, .time').bgIframe();
}

$('.date').datepicker({dateFormat: 'D M dd, yy', minDate:2, beforeShowDay: $.datepicker.noWeekends});
$('.datetime').datetimepicker({
    dateFormat: 'yy-mm-dd',
    timeFormat: 'h:m'
});
$('.time').timepicker({timeFormat: 'h:m'});
//--></script> 

It works great by I have one thing I would like to add to it.

I use the datepicker so my customers can choose a date when they can pick up an item.

I would like it to blank out the the next two days after it reaches 5.30pm EST.

So at 1pm on Monday I can only select Wednesday onwards. If it is 6pm Monday I can only order Thursday onwards.

Does anyone know how to do this? I couldn't quite figure it out from the API website.

Many Thanks

Peter

Upvotes: 0

Views: 2492

Answers (1)

Colleen
Colleen

Reputation: 25479

per the docs: http://jqueryui.com/datepicker/#min-max

you can set minDate: 2 depending on what time it is now.

var min = 1;
var currentTime = new Date();
if (currentTime.getHours() >=17 && currentTime.getMinutes() >=30){
    min = 2;
}

then pass min into minDate.

as ahren pointed out, though, this will be the user's time, not yours. If you want to find the timezone and adjust from there you can use getTimeZoneOffset http://www.w3schools.com/jsref/jsref_gettimezoneoffset.asp

Upvotes: 2

Related Questions