Tuesday, April 30, 2013

Submitting a date to Database from datepicker || PHP mysql insert date format



$date = mysql_real_escape_string($_POST['date']);
$new_date = date('Y-m-d',strtotime($date));

$sql="INSERT INTO some_table (date)
VALUES
('$new_date')";

Example 2 

//get the correct format
$new_date = date('Y-m-d',strtotime($_POST['date']));

//then you can insert that date

$insert = 'INSERT INTO some_table (field1) VALUES("'.mysql_real_escape_string($new_date).'")';

0 Comments:

Post a Comment