PDA

View Full Version : Inserting a future time into MySQL


danielwarner
01-24-2006, 10:38 PM
how do you add in a future time into mysql... im using the MySQL timestamp function but i want to be able to add in a future date of a gig using drop-down box's like DD - MM - YYYY - TIME ...etc

danielwarner
01-25-2006, 10:35 AM
This is how far i have got but it doesnt seem to work. it just brings back the error: "You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '('2003-12-31 01:02:03'); , '84.71.151.79')' at line 1"

$sql = "INSERT INTO `news` ( `title` , `post` , `author` , `timestamp` , `ip` ) VALUES ('$title', '$post', '$author', DATE('2003-12-31 01:02:03') , '$ip');";

can someone please help fix this :)

MRMAN
01-25-2006, 10:42 AM
I think you will need to do something like this

$sql = "INSERT INTO `news` ( `title` , `post` , `author` , `timestamp` , `ip` ) VALUES ('$title', '$post', '$author', '". date('2003-12-31 01:02:03')."' , '$ip');";


note: i have encased the data in single quotes and escaped out of the string.

Hope this helps
MRMAN

danielwarner
01-25-2006, 11:16 AM
that didnt insert the time 2003-12-31 01:02:03

MRMAN
01-25-2006, 11:28 AM
opps my mistake i over looked one small section.
you might need this

date("Y m d H:i:s", strtotime("2003-12-31 01:02:03"))

this is to replace the data() that is in the statment i made above

danielwarner
01-25-2006, 12:32 PM
You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '('Y m d H:i:s', strtotime('2003-12-31 01:02:03'))

danielwarner
01-25-2006, 10:47 PM
can someone help please :)

kiswa
01-25-2006, 11:00 PM
Let me get this right... you have a form that lets you enter the day, month, year, and time of an event?

Then why not have your MySQL query be:


$sql = "INSERT INTO news SET title='$title', post='$post', author='$author', timestamp='".$year.'-'.$month.'-'.$day.' '.$hour.':'.$minute.':'.$second."', ip='$ip'";


Where the $year, $month, $day, $hour, $minute, and $second variables come from your form.

What do you think?