angello Posted August 24, 2012 Share Posted August 24, 2012 hi, i have a form that get?s date from a datepicker like this 12/05/2012 in 1 variable, but i want it after get the date from the datepicker, to put date it in 3 diferent variables: $day $month $year How can i do this? code example: <form action="destiniaXMLrequest.php" method="post" name="getxmlrequest"> <label>Check In</label> <input type="date" name="CheckIn" id="checkinflight"/><br/> <label>Check Out</label><input type="date" name="CheckOut" id="checkoutflight"/><br/> <input type="submit" value="Send" /> <input type="reset" value="Clear Fields" /> </form> this is the php code: $checkin_day = $_POST['CheckIn']; $checkout_day = $_POST['CheckOut']; echo "this is the data you enter in the form:<br>"; echo $checkin_day."<br>"; echo $checkout_day."<br>"; echo("What i want to do is to put the date of the datepicker (in 1 variable) in 3 diferent variables<br>"); echo("like this:<br>"); echo ('$checkin_day'."<br>"); echo ('$checkin_month'."<br>"); echo ('$checkin_year'."<br>"); Thanks for any help guys Quote Link to comment Share on other sites More sharing options...
Christian F. Posted August 24, 2012 Share Posted August 24, 2012 The real question is why do you want it in three separate variables? What's your end goal with doing it like that? To answer your question, check out explode () and list (). Though, I'm almost certain you're doing it, whatever it is you're doing, in an overly complicated manner. Quote Link to comment Share on other sites More sharing options...
angello Posted August 24, 2012 Author Share Posted August 24, 2012 thanks for your answer cristianF, the thing is that im building a travel simple webpage, and i have a date form where you select the date from a datepicker as i explain in my post, but to see the results of hotels/flights (im in an traveling affiliate program) they ask me to interrogate or to ask their server for this search in 3 diferen variables, so you would pick the date automatic from a datepicker in my web page like this: 15/05/2012,with only 1 click, but i have to send the xml request to their server like this: find me a flight to this date: $day $month $year See now why im asking to solve this? ill try what you just told me, but if with this explanation you thing there is an easier way please let me know, thanks again Quote Link to comment Share on other sites More sharing options...
Psycho Posted August 24, 2012 Share Posted August 24, 2012 I completely agreed with ChristianF's original response. But, if you are required to send the data in three separate variables, then that is what you must do. But, if you are storing this data in the database you should absolutely be storing it as a valid date value and not separate values. Only separate into the components at the time that you need to. ChristianF's solution is the one I would go with if you are taking the submitted value directly and parsing it out. list($month, $day, $year) = explode('\', $_POST['CheckIn']); Quote Link to comment Share on other sites More sharing options...
Christian F. Posted August 25, 2012 Share Posted August 25, 2012 Ah, then you're not the one doing it in an overly complicated manner, at least not willingly. So, yeah, I can see why. Psycho's solution is almost correct, he just forgot to escape the slash. Other than that, he's right on the money with everything he wrote. Quote Link to comment Share on other sites More sharing options...
angello Posted August 25, 2012 Author Share Posted August 25, 2012 thank both of you guys, it works just great with explode, let me show you what im doing, i bought a template and i want to have a travel site with an affiliate program, and i dont know too much php as you can see but im learning, you can see the template http://www.vacacionesytours.com/ please go to the left and go to the "Prepare for traveling Form", then click on the field to choose the date (date picker was not part of the template, i put it myself from jquery ui) so you can see the date you choosed, but in the backend i will send the date in 3 variables, day, month and yeat to the server and i will get an xml response and then with html and css i have to show the results , hotels, flight etc. so if you have a better idea (exept to change the form to have 3 fields for date) i?m all ears Thkans again pals christianf and sycho Quote Link to comment Share on other sites More sharing options...
DavidAM Posted August 25, 2012 Share Posted August 25, 2012 ChristianF's solution is the one I would go with if you are taking the submitted value directly and parsing it out. list($month, $day, $year) = explode('\', $_POST['CheckIn']); It looks to me like the OP's datetime picker is sending DD/MM/YYYY ... ... from a datepicker in my web page like this: 15/05/2012, ... in which case, the PHP would be: list($day, $month, $year) = explode('/', $_POST['CheckIn']); (Why was that a backslash?) Quote Link to comment Share on other sites More sharing options...
Christian F. Posted August 25, 2012 Share Posted August 25, 2012 Sounds like you've got the best possible solution, considering the limitations the backend servers impose on you. So don't worry about it. Glad we could help. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.