gum1982 Posted November 7, 2009 Share Posted November 7, 2009 hello ive got a field in my database called dated i want to insert a future date and time into this field from a form. Ive used the now function and it works fine but i want to be able to set a future time? <?php require_once('settings.php'); $recipient = $_POST['recipient']; $sender = $_POST['sender']; $message = $_POST['message']; $datetime = new DateTime($_POST['datetime']); $datetime->format("d-m-Y H:i:s"); // insert message mysql_select_db($database_conn, $conn); $sql = "insert into tbl_outbox (recipient,sender,message,dated ) values ('$recipient','$sender','$message','$datetime') "; $result = mysql_query($sql, $conn) or die(mysql_error()); ?> How do i set the time to the right format so that it inserts correctly. Ive set the field in mysql to datetime. Any help please? Link to comment https://forums.phpfreaks.com/topic/180691-inserting-future-date-and-time-into-database/ Share on other sites More sharing options...
Cardale Posted November 7, 2009 Share Posted November 7, 2009 Without me doing it for you this is the best help I can give. http://www.php.net/manual/en/function.date-add.php Link to comment https://forums.phpfreaks.com/topic/180691-inserting-future-date-and-time-into-database/#findComment-953378 Share on other sites More sharing options...
The Little Guy Posted November 8, 2009 Share Posted November 8, 2009 Well, you have your format wrong... Mysql is: YYYY-MM-DD HH:MM:SS you have: DD-MM-YYYY why are you even using that class? it really isn't necessary... date("Y-m-d H:i:s", strtotime("now +24 hours")); you might also want to use a "timestamp" for your field type Link to comment https://forums.phpfreaks.com/topic/180691-inserting-future-date-and-time-into-database/#findComment-953523 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.