justlukeyou — 2013-04-10T16:24:55-04:00 — #1
I am looking to implement a date picker to allow users to select a start and date. I have been recommended to use the jquery date picker however I am struggling to see how I implement into PHP.
Do I need to wrap the code into an input box or do I use the existing input box?
avram — 2013-04-10T16:40:52-04:00 — #2
Date picker is related to UI so it's not related to PHP but to jQuery. You can existing input box and call jQuery datepicker() on it to turn it to jQ date picker.
justlukeyou — 2013-04-10T16:50:16-04:00 — #3
Not totally sure what you mean. Do I set up a PHP input box and insert the jQuery code into it?
avram — 2013-04-10T18:23:35-04:00 — #4
There is no such thing as PHP input box (at least not that I know of). You just place ordinary HTML input and call jQuery UI datepicker on it, if you want chosen date to be filled in that input box.
See example: http://jsfiddle.net/7dQLH/1/
justlukeyou — 2013-04-10T18:33:19-04:00 — #5
So do I set that code into a form with a submit button?
avram — 2013-04-10T19:43:30-04:00 — #6
Yes, you can place it into form and pass it to PHP script using regular POST or GET form submit.
justlukeyou — 2013-04-11T15:10:30-04:00 — #7
It was actually much easier than I thought it was, however I am having problems creating two datepickers on the same page. I am trying to use datepicker and datepicker1 for the start and end date. However what configuration I try doesn't seem to work.
Can you advise how to use two functions on the same page?
$( "#datepicker" ).datepicker();
$( "#datepicker1" ).datepicker1();
avram — 2013-04-11T15:41:59-04:00 — #8
$( "#datepicker, #datepicker1" ).datepicker();
justlukeyou — 2013-04-12T15:30:17-04:00 — #9
I can insert the dates into the table as a text format. However understandably I cant use it as value to calcuate with.
I have tried changing the 5 different date and times available in MyAdmin but I couldn't get that to work.
Do I need to transfer the date value into a number and treat it as an excel calculation or does MySQL treat dates as valuables which can be calculated.
I did find this but it states it is an eglish date but JQuery provides the US date format.
avram — 2013-04-12T15:57:02-04:00 — #10
You can either use unix timestamp or mysql's date format. I personally tend to use unix timestamp.
Take a look at this: http://api.jqueryui.com/datepicker/#method-getDate
That will give you selected date in form of JS Date object. To convert Date object to unix timestamp see this: http://www.w3schools.com/jsref/jsref_gettime.asp
Note that JS uses milliseconds for unix timestamp while PHP uses seconds, so you'd need to divide this number with 1000 either in JS or in PHP before working with this number later.
Or, you can make input box read-only (so it must be filled using the date picker) and then construct unix timestamp later in PHP. Check this: http://php.net/manual/en/function.mktime.php