Thebatfink
Active Member
- Joined
- Apr 8, 2007
- Messages
- 410
Hi. I have a problem with date formats driving me crazy. I have a source workbook which has dates in UK format DD/MM/YYYY. When I open this source file and look at the cell formatting, it is Date Type and is DD/MM/YYYY.
I read the contents of the workbook to a recordset and populate to an array:
But when I output this array to my workbook, the dates are getting confused with US formats. I added a watch to sapDeliveryList and I see for example sapDeliveryList(1,0) value is #09/02/2024# and the type is Variant/Date. But when I output this array to workbook, the date is displaying as 02/09/2024. My machine is all setup for United Kingdom date time formats. Any way to address this??
Thanks
James
I read the contents of the workbook to a recordset and populate to an array:
VBA Code:
Dim cnn As ADODB.Connection
Dim rs As ADODB.Recordset
Set cnn = New ADODB.Connection
Set rs = New ADODB.Recordset
Dim conStr As String
conStr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source='" & exportFilePath & exportFileName & "';" & _
"Extended Properties=""Excel 12.0;HDR=YES;IMEX=1;"";"
Dim strSQL As String
strSQL = "SELECT * FROM [Sheet1$]"
cnn.Open conStr
rs.Open strSQL, cnn, adOpenStatic, adLockOptimistic, adCmdText
Dim sapDeliveryList As Variant
If rs.Fields.Count >= 1 Then
sapDeliveryList = rs.GetRows
End If
But when I output this array to my workbook, the dates are getting confused with US formats. I added a watch to sapDeliveryList and I see for example sapDeliveryList(1,0) value is #09/02/2024# and the type is Variant/Date. But when I output this array to workbook, the date is displaying as 02/09/2024. My machine is all setup for United Kingdom date time formats. Any way to address this??
Thanks
James