P
Purnima
Hi,
I am trying to execute a SQL Stored procedure from Excel using VBA. Apart
from 2 string inputs, this proc also accepts two datetime imputs. When these
dates are passed via VBA, they are in the format "dd/mm/yyyy. However, the
SQL Server does not seem to accept dates passed in this format.
Applying different date formats in VBA does not help because eventually when
the dates shoot from Excel to SQL Server, they are in the format
"dd/mm/yyyy". I don't want to change the regional settings of the machine,
since it will only be a temporary solution.
This is the part of the code where I pass the date inputs to the procedure:
Dim prm As ADODB.Parameter
Set prm = cmd1.CreateParameter("StartDate", adDate, adParamInput)
cmd1.Parameters.Append prm
cmd1.Parameters("StartDate") = sd
Set prm = cmd1.CreateParameter("EndDate", adDate, adParamInput)
cmd1.Parameters.Append prm
cmd1.Parameters("EndDate").Value = ed
Even though the code does not throw an error, the recordset does not return
anything. If I try passing dates like "2009-01-31" (yyyy-mm-dd), then the
recordset returns the expected output.
Is there any way, I can force Excel to pass dates in the format "yyyy-mm-dd"
without having to change the systems date time format settings?
Thanks,
Purnima
I am trying to execute a SQL Stored procedure from Excel using VBA. Apart
from 2 string inputs, this proc also accepts two datetime imputs. When these
dates are passed via VBA, they are in the format "dd/mm/yyyy. However, the
SQL Server does not seem to accept dates passed in this format.
Applying different date formats in VBA does not help because eventually when
the dates shoot from Excel to SQL Server, they are in the format
"dd/mm/yyyy". I don't want to change the regional settings of the machine,
since it will only be a temporary solution.
This is the part of the code where I pass the date inputs to the procedure:
Dim prm As ADODB.Parameter
Set prm = cmd1.CreateParameter("StartDate", adDate, adParamInput)
cmd1.Parameters.Append prm
cmd1.Parameters("StartDate") = sd
Set prm = cmd1.CreateParameter("EndDate", adDate, adParamInput)
cmd1.Parameters.Append prm
cmd1.Parameters("EndDate").Value = ed
Even though the code does not throw an error, the recordset does not return
anything. If I try passing dates like "2009-01-31" (yyyy-mm-dd), then the
recordset returns the expected output.
Is there any way, I can force Excel to pass dates in the format "yyyy-mm-dd"
without having to change the systems date time format settings?
Thanks,
Purnima