jaxstorm
asked on
Converting PHP Date dd/mm/yyyy to SQL date YYYY-MM-DD
I'm having an annoying problem.
Got a date textbox where the entry is dd/mm/yyyy and I've converted the date for SQL into YYYY-MM-DD.
Then I run the checkdate command to confirm it's a valid date ;
it checks the date fine, but then, when putting it into the DB it puts it in mm-dd-yyyy format.
So, if I enter 31/7/2008 it'll convert the 31 into months and end p with some date thats in 2010!
Got a date textbox where the entry is dd/mm/yyyy and I've converted the date for SQL into YYYY-MM-DD.
Then I run the checkdate command to confirm it's a valid date ;
it checks the date fine, but then, when putting it into the DB it puts it in mm-dd-yyyy format.
So, if I enter 31/7/2008 it'll convert the 31 into months and end p with some date thats in 2010!
$Header = $_POST['Header'];
$Yeargroup = $_POST['Yeargroup'];
$Details = $_POST['Details'];
$Footer = $_POST['Footer'];
$Deadline = $_POST['Deadline'];
$Date = $_POST['Date'];
list($DD,$MM,$YY) = explode("/",$Date);
if(!checkdate($MM,$DD,$YY))
{
echo 'The date is invalid, please enter a date in the format
DD/MM/YY';
}else{
$Date = date('Y-m-d', strtotime($Date));
$Query="INSERT INTO bulletin (Header, YearGroup, Details, Deadline, Footer, Date)VALUES
('$Header','$Yeargroup','$Details','$Deadline','$Footer','$Date')";
mysql_query($Query) or die ('Error updating database');
printf ("Bulletin Item Added<br><br><br>Refreshing...");
}
?>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Open in new window