Jump to content

SQL error when trying to insert date into database


Recommended Posts



I keep recieving the following error:


"The conversion of char data type to smalldatetime data type resulted in an out-of-range smalldatetime value"


everytime I try and enter a date in the format of 12/05/2005 into my DB.


my code looks like


//Grab date for entry into database                            
$day = date("j");
$month = date("n");
$year = date("Y");
$date = date('d/m/Y', mktime(0, 0, 0, $month, $day, $year));
// Retrieve answer to question 1 and display
$booking = $_POST['holdingName1'];
echo ("<b>$booking</b>");
// query to add sigle answered form data into database
$insert_query = "INSERT INTO answers (id, qid, surveyNum, answer, date) VALUES ('$var', '1', '1', '$booking', '$date')";

$result = odbc_exec($connection, $insert_query);


$date returns the format stated above but it wont allow me to enter itno the DB...WHY!!!!!


Please...Please...someone help


Best Regards



Link to comment
Share on other sites

  • 3 weeks later...
This thread is more than a year old.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • 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.