Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Nov 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    how to separate date in 3 variable?

    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:
    Code:
    <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:
    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

  • #2
    Senior Coder Len Whistler's Avatar
    Join Date
    Jul 2002
    Location
    Vancouver, BC Canada
    Posts
    1,323
    Thanks
    26
    Thanked 100 Times in 100 Posts
    PHP Code:
    <?php
    $date 
    "12/05/2012";
    $results explode("/",$date);

    echo 
    "Month: $results[0]<br>";
    echo 
    "Day: $results[1]<br>";
    echo 
    "Year: $results[2]<br>";
    ?>

    Ouput
    Code:
    Month: 12
    Day: 05
    Year: 2012

    ----
    Leonard Whistler


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •