We help IT Professionals succeed at work.

Date is inserting as 0000-00-00  in mysql

date format in Mysql is yyyy-mm-dd

how to store  yyyy-mm-dd in mysql from this Format  mm/dd/yyyy

Is there anything i'm missing here

example : $date_start1 = '09/25/2015'; (MM/DD/YYYY)


$date_start1 = $_POST['datestartinput'];
$date_start1 =  DateTime::createFromFormat('m/d/y', $date_start1);
$date_start = $date_start1->format('Y-m-d');
Comment
Watch Question

Most Valuable Expert 2011
Top Expert 2016
Commented:
Most Valuable Expert 2011
Top Expert 2016

Commented:
In a nutshell:

1. Use the ISO-8601 standard format for all internal representations of the date/time values
2. Reformat these values from the ISO standard to anything you want in the "view" scripts.

By doing these two things you will preserve the integrity of your data and you will control the display.
Most Valuable Expert 2018
Distinguished Expert 2019
Commented:
You're passing in the wrong format to createFromFormat(). If your date has a 4 digit year, then you need the capital Y

$date_start1 =  DateTime::createFromFormat('m/d/Y', $date_start1);

Open in new window