Currently I'm using html time picker, but wouldn't mind using Javascript/Jquery/Ajax instead. The problem I'm trying to solve is this:
you are a customer, you ordered x from an employee. that x has a duration (start_time - end_time). The time form data is saved in $customer_time
. Note that I had to store the days as varchar. but my issue is not with date, it's with time.
The sql query I have is this (feel free to make it better if you could)
SELECT employee_id, product_start_time, product_end_time, date FROM orders
WHERE NOT (
employee_id ='$employee_id'
AND res_date = '$res_date'
AND $customer_time =TIMEDIFF ('product_start_time','product_end_time')
)
I guess I wrote timediff right, if not please correct it as I have never used it before, the idea is
$customer_time = start_time - end_time
Anyhow, if the employee is free, then the customer can proceed with the reservation, otherwise, the time_ picker field should be disabled. I need a time picker like the html one, but one that I can work with and disable the time. I don't want a time picker where I select default time from a list of intervals.
So please
Update
Perhaps a better version of my query is to use INTERVAL instead of timediff, since every product has a duration in minutes, few have durations in hours, but mostly minutes.
My initial idea was to create a time field that keeps checking for availability, like you check for available usernames, in a username field using ajax, don't know if that would work though.
@Lynob here is timepicker with disabled times. You need to put more time in the disabled array and it will work.
var input = $('#input-a');
var dissabledTime = ["11:00", "12:00", "13:00", "14:00"];
input.clockpicker({
autoclose: true,
afterDone: function() {
console.log(dissabledTime.indexOf($('#input-a').val()));
if(dissabledTime.indexOf($('#input-a').val()) != -1)
{
alert("My dear select other time i'm busy :)");
$('#input-a').val('');
}
},
});
Here is the whole fiddle
Regards,
George
Assuming from what you are trying to say :
Store selected dates to mysql in date format. While querying, check the selected dates per user or how you wish to do it. Then proceed in this way.
This will be per session. You have to store the results in an array :
var disableddates = ["02-14-2015", "05-19-2013", "12-20-2014", "another one"];
function DisableSpecificDates(date) {
var string = jQuery.datepicker.formatDate('dd-mm-yy', date);
return [disableddates.indexOf(string) == -1];
}
You have to call the datepicker function later on.
$(function() {
$("#date").datepicker({
beforeShowDay: DisableSpecificDates
});
});
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Tite</title>
</head>
<body>
<input id="date" type="text">
</body>
</html>
You have to include jquery datepicker plugin and dependencies.