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.
MySQL ServerASPDatabases

Avatar of undefined
Last Comment
Scott Fell

8/22/2022 - Mon
SStory

TRY '2015/06/04 00:00:00'
Scott Fell

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.
Big Monty

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
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
SStory

I was suggesting that the date may need to be quoted and in the standard format to be acceptable.
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
Big Monty

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Scott Fell

The last parameter should be

 MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param5", 135, 1, -1, UploadFormRequest("SelectedDate")) ' adVarWChar
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.