Q:

Passing date as parameter to a php file

I'm trying to pass a date parameter to a php file so it could insert it into a MySQL table. This is how the date is being transferred:
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss%20yyyy-MM-dd");
String currentDateandTime = sdf.format(new Date());

And this is the part in the php file that tuches the date:
$date = $_GET['dt'];

$dateFirst = substr($date, 0, 8);
$dateSecond = substr($date, 11, 10);
$dateComplete = $dateFirst . ' ' . $dateSecond;

$sql=mysql_query("INSERT INTO User
VALUES (NULL, '$uName', '$pass', '$mail', '$disName', 0, '$dateComplete')");

The date field in the table is dateTime. The procedure doesn't fall but the date in the table looks like this: "00:00:00 0000-00-00". Can someone please tell me what am I doing wrong? Thank you in advance!

A:

Switch the order of the concatenation:
$dateComplete = $dateSecond . ' ' . $dateFirst;

The way it is currently written you will be passing '11:07:19 2014-07-09' which is not a date format the MySQL understands.

A:

You can use the mysql function NOW() or just insert the formatted php date
$sql=mysql_query("INSERT INTO User
VALUES (NULL, '$uName', '$pass', '$mail', '$disName', 0, NOW())");

OR
$dateComplete = date('Y-m-d H:i:s');
$sql=mysql_query("INSERT INTO User
VALUES (NULL, '$uName', '$pass', '$mail', '$disName', 0, '$dateComplete')");

