Click here to Skip to main content
15,885,914 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi,

I'm using jquery datetimepicker.

I don't want to allow user to select any past date other than current or future date.
I have achieved above functionality. All, i'm facing problem is with time.

I don't want to allow user to select any past time other than current or future time, i.e. if current time is 1:00 pm, user can't select past time to 1:00 pm


How can I achieve this?

What I have tried:

function getCurrentTime(date) {
var hours = date.getHours(),
minutes = date.getMinutes(),
ampm = hours >= 12 ? 'pm' : 'am';

hours = hours % 12;
hours = hours ? hours : 12; // the hour '0' should be '12'
minutes = minutes < 10 ? '0'+minutes : minutes;

return hours + ':' + minutes + ' ' + ampm;
}

var time = new Date().getTime();
var currentdate = new Date(time);
var datetime = currentdate.getDate() + "/"
+ (currentdate.getMonth()+1) + "/"
+ currentdate.getFullYear() + " "
+ currentdate.getHours() + ":"
+ currentdate.getMinutes() ;
//var time = currentdate.getHours() + ":" + currentdate.getMinutes();


$("#myDate").datetimepicker({
dayOfWeekStart: 1,
minDate: 0,
minTime: getCurrentTime(new Date()),
setDate:currentdate,
format: 'd/m/Y H:i',
formatTime: 'H:i',
formatDate: 'd/m/Y',
ampm: true,
step: workingHrSlot
//onChangeDateTime: logic,
//onShow: logic
});
Posted
Comments
ZurdoDev 6-May-16 7:37am    
This is asked all the time. I suggest googling.
Prateek Dalbehera 21-May-16 13:37pm    
Use moment.js and set time values accordingly, it will reduce your code and also easier for you...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900