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).'")';

About the Author

Expert writer helping professionals grow their knowledge through well-researched content and strategic insights.

Read the previous article
Read the next article

Popular Posts