Jump to content

Inserting future date and time into database


gum1982

Recommended Posts

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?

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.