Wednesday, 7 August 2013

Create mysql compatible Date from variables in PHP

Create mysql compatible Date from variables in PHP

I have a field set to type date in a mysql table. I get day, month and
year from user and at the moment I have the values returned like this:
[start_dateMonth] => 08 //$stardMonth
[start_dateDay] => 7 //$startDay
[start_dateYear] => 2013 //$startYear
How can I convert this to a valid date that I can easily insert in the
database?
This is my own code, but for some reasons the browser just shows a blank
screen with no source code inside:
$format = 'Y-m-d H:i:s';
$start = DateTime::createFromFormat($format,
"$startYear-$startMonth-$startDay $startHour:$startMinutes:00");
echo $start;

No comments:

Post a Comment