Link to home
Start Free TrialLog in
Avatar of AndersonHitchen
AndersonHitchen

asked on

Alter Date column in MySQL - assistance

I am getting the following error on an image upload page that writes to a mysql database.

 [ODBC 5.1 Driver][mysqld-5.6.22-log]Incorrect date value: ' 4/6/2015' for column

I had to recreate the table as it was missing so I am guessing that I created the column incorrectly and now need to alter it.

Any help would be appreciated.
Avatar of SStory
SStory
Flag of United States of America image

TRY '2015/06/04 00:00:00'
You may need to format the date.  

MyDate=cdate("4/6/2015")
MyNewDate = year(MyDate)&"-"&right("0"&month(MyDate),2)&"-"&right("0"&day(MyDate),2)

Open in new window


Use MyNewDate to submit to mysql.
you may want to consider using parameterized queries, thus eliminating issues like this

https://www.experts-exchange.com/Programming/Languages/Scripting/ASP/A_3626-ASP-Classic-Using-Parameterized-Queries.html
I was suggesting that the date may need to be quoted and in the standard format to be acceptable.
Avatar of AndersonHitchen
AndersonHitchen

ASKER

Hi Again

As in my question I only need to alter the table not the code as the code works fine normally. Its only due to the fact that I have had to recreate the table for the upload data which has a datefield in it and I have not created that column correctly.

I was hoping that someone might have a solution to this.

Here is a snipet of code from the upload page that relates to the date which again shows that I only need to alter the date column to suit input.

Set MM_editCmd = Server.CreateObject ("ADODB.Command")
    MM_editCmd.ActiveConnection = MM_connilease_STRING
    '                                                                        1                  2                        3                        4                              5                              
    MM_editCmd.CommandText = "INSERT INTO carimages (makeID, modelID, modelYear, fldImage, dateAdded) VALUES (?, ?, ?, ?, ?)"
    MM_editCmd.Prepared = true
    MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param1", 5, 1, -1, MM_IIF(UploadFormRequest("make"), UploadFormRequest("make"), null)) ' adDouble
         MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param2", 5, 1, -1, MM_IIF(UploadFormRequest("models"), UploadFormRequest("models"), null)) ' adDouble
      MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param3", 202, 1, 50, UploadFormRequest("year")) ' adVarWChar
      MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param4", 202, 1, 50, UploadFormRequest("img1")) ' adVarWChar
      MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param5", 202, 1, 50, UploadFormRequest("SelectedDate")) ' adVarWChar
    MM_editCmd.Execute
    MM_editCmd.ActiveConnection.Close

Cheers for the replies
ASKER CERTIFIED SOLUTION
Avatar of Big Monty
Big Monty
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
The last parameter should be

 MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param5", 135, 1, -1, UploadFormRequest("SelectedDate")) ' adVarWChar