Hello,
I have an old piece of VB6 code that accesses SQL to determine the date format in order to provide consistency throughout the program regardess of how the computer date is formatted. Could anyone help with this conversion or provide an alternate method?
Thank you for your assistance.
If at first you don't succeed, then sky diving wasn't meant for you!
I have an old piece of VB6 code that accesses SQL to determine the date format in order to provide consistency throughout the program regardess of how the computer date is formatted. Could anyone help with this conversion or provide an alternate method?
Code:
Public Function SQLServer_DateFormat(ByVal pValue As Object) As String
'// Returns the proper string Date format from a variant.
Dim cmd As ADODB.Command
Dim rs As ADODB.Recordset
Dim l_lngLangID As Long
Dim l_datValue As Date
If IsDate(pValue) Then
l_datValue = CDate(pValue)
'// Get the SQL Server default language.
rs = pihCONN.Execute("sp_configure 'default language'")
If Not (rs.BOF And rs.EOF) Then l_lngLangID = rs.Fields("config_value")
rs.Close()
rs = Nothing
'// Get the date format used by SQL server.
rs = pihCONN.Execute("sp_helplanguage")
If Not (rs.BOF And rs.EOF) Then
rs.MoveFirst()
Do Until rs.EOF
If rs.Fields("langid") = l_lngLangID Then
Select Case rs.Fields("dateformat")
Case "dmy"
SQLServer_DateFormat = Day(l_datValue) & "/" & Month(l_datValue) & "/" & Year(l_datValue)
Case "mdy"
SQLServer_DateFormat = Month(l_datValue) & "/" & Day(l_datValue) & "/" & Year(l_datValue)
Case "ymd"
SQLServer_DateFormat = Year(l_datValue) & "/" & Month(l_datValue) & "/" & Day(l_datValue)
Case Else
SQLServer_DateFormat = CStr(pValue)
End Select
Exit Do
End If
rs.MoveNext()
Loop
Else
SQLServer_DateFormat = CStr(pValue)
End If '// Not (rs.BOF And rs.EOF).
rs.Close()
rs = Nothing
End If '// IsDate(pValue)
End Function
Thank you for your assistance.
If at first you don't succeed, then sky diving wasn't meant for you!