The function below works fine and outputs the correct result except it outputs the dates as strings and not as dates. How can I get it to output dates instead?
Function GetExpiries_YieldX(TradeDate As Date, Code As String) As Variant
'Create and open the connection
Dim oConnection As Connection
Set oConnection = New Connection
oConnection.ConnectionString = strConnectionStringYieldX
oConnection.Open
'Create the command object
Dim oCommand As Command
Set oCommand = New Command
oCommand.CommandType = adCmdText
Dim SQLString As String
SQLString = "SELECT DISTINCT Expiry" _
& " FROM MTM" _
& " WHERE TradeDate = ?" _
& " and Code = ?"
oCommand.CommandText = SQLString
oCommand.ActiveConnection = oConnection
oCommand.Parameters.Append oCommand.CreateParameter("Date", adDBTimeStamp, adParamInput)
oCommand.Parameters.Append oCommand.CreateParameter("Code", adVarChar, adParamInput, 50)
oCommand.Parameters.Item("Date").Value = TradeDate
oCommand.Parameters.Item("Code").Value = Code
Dim result As New ADODB.Recordset
Set result = oCommand.Execute
Dim resultA As Variant
'GetExpiries_YieldX = WorksheetFunction.Transpose(result.GetRows)
GetExpiries_YieldX = result.GetRows
oConnection.Close
End Function
datetype (SQL Server 2008 btw), I am putting the dates on the worksheet. At the moment I'm just converting them to dates doing this sort of thing:=DATE(LEFT(A2,4),MID(A2,6,2),RIGHT(A2,2))but I would prefer if they just came out as dates if possible. I find it very difficult to find decent documentation on how to write these sort of functions (i.e. vba functions that query sql server dbs) properly :/