I am using VBA to upload data from and Excel file into SQL Server. The date column in the CSV as I get is in the "mm/dd/yy format". How do I format the date to be in the SQL Server format "YYYY-MM-DD hh:mm:ss:000" before I pass it to the query to insert the record?
I declare the variable
Dim InvoiceDate As Date
I get the value from the workbook
InvoiceDate = row.Cells(5).Value
I insert into the table
INSERT INTO table(InvoiceDate) VALUES (" & InvoiceDate & ")
I end up with this:
1900-01-01 00:00:00.000
Format$.Format$(InvoiceDate,"YYYY-MM-DD hh:mm:ss:000")will do it.InvoiceDatein the code is assigned the value of an empty cell!