Hi guys... just a quick question.

so i have a form, where all users will input a date in format DD/MM/YYYY

i want to convert this into YYYY/MM/DD and then insert it into the mysql database.

this is the code i have created for the rearranging of the date:

<?php 
$pieces = explode("/", $_POST[eta]);
$predate = $_POST[eta];
$datey = echo('$pieces[2]-$pieces[0]-$pieces[1]');


echo "English date: $predate <br>";
echo "MySQL date: $datey";

?>

my problem is, that, as you can see on line 4 i am trying to get all of the pieces of the exploded date into one variable,,,, but i am recieving a parse error.

can anyone help? Thanks.

    $datey = $pieces[2].'-'.$pieces[0].'-'.$pieces[1];

    (no echo)

    but that leaves you with potential errors

    what happens if someone enters 31 February 2011?

    to handle that you can do:

    $datey = date('Y-m-d',strtotime($pieces[2].'-'.$pieces[0].'-'.$pieces[1]));

    which would output the valid date 3rd March, as in count terms that would be 31st Feb

      cretaceous wrote:

      which would output the valid date 3rd March, as in count terms that would be 31st Feb

      But March 3rd doesn't equal February 31st, because February 31st doesn't make any sense.

      I would much rather use something like [man]checkdate/man to verify that valid input was received and, if not, reject it and display an error message.

        Write a Reply...