JQuery UI datepicker: 1969 mapping, although I use strtotime

I have an application for reserving PHP + JQUERY numbers. I use the datepicker widget to select a date, and I ran into a problem. I am trying to convert the selected date (in dd / mm / yyyy format) to YYYY-mm-dd format to insert it into my database. When I select the first dates, it converts well, but when I select 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 repeat the result for testing:

  <?php if(isset($_POST['selectedDate'])) { $selectedDate=$_POST['selectedDate']; echo date('Ym-d',strtotime((string)$selectedDate)); } ?> 

Here is the image in my application: http://oi43.tinypic.com/29tv2c.jpg

1 : enter image description here

+6
source share
2 answers

In the end, I conveyed the problem. instead of converting it to PHP, I converted it to 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 problem with the date conversion function ()!

+1
source

What type of selected date do you store in MySQL? With the DATE data type, you just need to pass the "YYYY-MM-DD" format to the INSERT statement.

See this question for more details.

And also this http://dev.mysql.com/doc/refman/5.5/en/datetime.html

0
source

Source: https://habr.com/ru/post/912688/


All Articles