bravo14 Posted May 7, 2013 Share Posted May 7, 2013 Hi Guys I have got a datepicker on a site and have set the minDate to be tomorrow. <script> $(function() { $( "#delDate" ).datepicker({ dateFormat: 'd MM yy', changeMonth: true, changeYear: true, minDate: "+1D", constrainInput: true, beforeShowDay: noWeekendsOrHolidays }); }); </script> What I want to do is set the minDate to +2 if the time is after 5pm, anybody got any guidance on how to achieve this. Quote Link to comment https://forums.phpfreaks.com/topic/277748-datepicker-mindate-based-on-time-of-day/ Share on other sites More sharing options...
DarkKnight2011 Posted May 7, 2013 Share Posted May 7, 2013 Try this... <script> $(function() { $( "#delDate" ).datepicker({ dateFormat: 'd MM yy', changeMonth: true, changeYear: true, minDate: "+1D", constrainInput: true }); var currentdate = new Date(); if (currentdate.getHours() >= 17) { currentdate.setDate(currentdate.getDate() + 2); $( "#delDate" ).datepicker( "option", "minDate", currentdate); } }); </script> Quote Link to comment https://forums.phpfreaks.com/topic/277748-datepicker-mindate-based-on-time-of-day/#findComment-1428889 Share on other sites More sharing options...
DarkKnight2011 Posted May 8, 2013 Share Posted May 8, 2013 Did this work ok for you? could you please mark as answered if so, Thanks Quote Link to comment https://forums.phpfreaks.com/topic/277748-datepicker-mindate-based-on-time-of-day/#findComment-1429091 Share on other sites More sharing options...
jesruiz Posted May 21, 2013 Share Posted May 21, 2013 (edited) Try this... <script> $(function() { $( "#delDate" ).datepicker({ dateFormat: 'd MM yy', changeMonth: true, changeYear: true, minDate: "+1D", constrainInput: true }); var currentdate = new Date(); if (currentdate.getHours() >= 17) { currentdate.setDate(currentdate.getDate() + 2); $( "#delDate" ).datepicker( "option", "minDate", currentdate); } }); </script> I've been googling for a few hours and just stumbled upon this. It works great for me but how could I modify it to target a time with minutes like 11:30. Here's what I have but it's not working out so well. // Check time var currentdate = new Date(); var hour = now.getHours(); var mintues = now.getMinutes(); // if time is after 11:30 change start date. if ((hour*60 + mintues) >= 690) { currentdate.setDate(currentdate.getDate() + 2); $( "#delnote" ).datepicker( "option", "minDate", currentdate); } Thanks, Jesse Edited May 21, 2013 by jesruiz Quote Link to comment https://forums.phpfreaks.com/topic/277748-datepicker-mindate-based-on-time-of-day/#findComment-1431442 Share on other sites More sharing options...
jesruiz Posted May 21, 2013 Share Posted May 21, 2013 Fixed it, thanks for the initial start! // Check time var currentdate = new Date(); var hour = currentdate.getHours(); var mintues = currentdate.getMinutes(); // if time is after 11:30 change start date. if ((hour*60 + mintues) >= 690) { currentdate.setDate(currentdate.getDate() + 2); $( "#delnote" ).datepicker( "option", "minDate", currentdate); } Quote Link to comment https://forums.phpfreaks.com/topic/277748-datepicker-mindate-based-on-time-of-day/#findComment-1431446 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.