tejama Posted June 12, 2007 Share Posted June 12, 2007 Hey all, I'm trying to insert a date/time into Mysql. I'm entering a future date in a text box similar to '2007-12-31 6:00:00' and the field in Mysql I'm trying to insert it into is of the type datetime. I'm trying $date = $_POST['date']; $newdate = date(Y-m-d H:i:s, strtotime($date); Then I try to insert $newdate but no joy. Can anyone suggest what's going wrong here? Quote Link to comment https://forums.phpfreaks.com/topic/55307-solved-datetime-help/ Share on other sites More sharing options...
SycoSyco Posted June 12, 2007 Share Posted June 12, 2007 Try this, I think it's because you're missing quotes. Try echoing the query to the page first to see if you're getting the date in the format before trying to enter it. I'm presuming the date is a Unix timestamp too. $newdate = date("Y-m-d H:i:s", strtotime($_POST['date']); EDIT: Ohhh you're entering the date into a field in the correct format? Then you can just enter it as shown below. Quote Link to comment https://forums.phpfreaks.com/topic/55307-solved-datetime-help/#findComment-273398 Share on other sites More sharing options...
The Little Guy Posted June 12, 2007 Share Posted June 12, 2007 This is how a DATETIME field is formatted in MYSQL: YYYY-MM-DD HH:MM:SS $query = "INSERT INTO table (`datetime`) VALUES ('{$_POST['date']}')"; $sql = mysql_query($query)or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/55307-solved-datetime-help/#findComment-273400 Share on other sites More sharing options...
tejama Posted June 12, 2007 Author Share Posted June 12, 2007 Ahhh...right you are Little Guy. Thanks for the help. SycoSyco - made a typo and forgot to include the quotes...they were in my source code though. Quote Link to comment https://forums.phpfreaks.com/topic/55307-solved-datetime-help/#findComment-273403 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.