I have PHP+JQUERY room reservation application. I'm using the datepicker widget for picking date and I encounter a problem. I try to convert the selected date (in dd/mm/yyyy format) to YYYY-mm-dd format in order to INSERT it to my database. When I pick the first dates, it converts well but when I pick other dates, I see the date 1969-12-31. Here is my JQUERY code:
$(function() {
$( "#datepicker" ).datepicker({
showOn: "button",
buttonImage: "images/calendar.gif",
buttonImageOnly: true,
minDate: 0,
maxDate: "+3W",
dateFormat: "dd/mm/yy",
beforeShowDay: function (date) {
var day = date.getDay();
return [(day == 0 || day == 1 || day == 2 || day == 3 || day == 4), ''];
},
onSelect: function(dateText) {
$("#registration").load("room.php #registration", {selectedDate: dateText}, function() {
$( "input:submit, a, button", ".registration" ).button();
$( "a", ".registration" ).click(function() { return false; });
});
}
});
});
And then i echo the result for testing:
<?php if(isset($_POST['selectedDate']))
{
$selectedDate=$_POST['selectedDate'];
echo date('Y-m-d',strtotime((string)$selectedDate));
}
?>
Here is an image in my app: http://oi43.tinypic.com/29tv2c.jpg
1:
inside the jQuery script code just paste the code. $( ". selector" ). datepicker({ dateFormat: 'yy-mm-dd' });
To change the position of the jQuery UI Datepicker just modify . ui-datepicker in the css file. The size of the Datepicker can also be changed in this way, just adjust the font size.
Define beforeShowDay within datepicker() method. In the function create a new date format according to the defined format (dd-mm-yyyy) in an Array. Check for the date in the Array with $. inArray() method if it is available then return [true, "highlight", tooltip_text]; otherwise return [true] .
You can restrict the users from selecting a date within the particular range by specifying MinDate and MaxDate properties. The default value of MinDate property is 1/1/1920 and MaxDate property is 12/31/2120 . Dates that appears outside the minimum and maximum date range will be disabled (blackout).
Eventually i by passed the problem. instead of converting it in PHP, i converted it in JS:
onSelect: function(dateText) {
//Converting the date format by spliting the date.
var dt= dateText;
var arrDt = dt.split('/');
var newDt = arrDt[2] + "-" + arrDt[1] + "-" + arrDt[0];
//Loading the rooms div acoording to the sent selected date in JSON format
$("#registration").load("room.php #registration", {selectedDate: newDt}, function() {
$( "input:submit, a, button", ".registration" ).button();
$( "a", ".registration" ).click(function() { return false; });
});
}
But i still don't know what caused the date() function conversion problem!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With