If you haven't localized SQL Server for your language, the default date format is the American one: DD/MM/YY. You may need to display a date in different formats, and you can solve this problem with the help of SQL DMO. A possible solution is using the T-SQL CONVERT() function to show the date with a certain format, helped by the ExecuteWithResults method of SQL DMO that is able to get the proper date translation through a SQL statement, as shown in the following piece of code: |
Click here to copy the following block | Dim oSQLServer As SQLDMO.SQLServer Dim oQueryResult As SQLDMO.QueryResults
Set oSQLServer = New SQLDMO.SQLServer oSQLServer.LoginTimeout = 15 oSQLServer.ODBCPrefix = False oSQLServer.Connect "MySQLServer", "sa", vbNullString Set oQueryResult = oSQLServer.ExecuteWithResults _ ("SELECT CONVERT(char(12), GETDATE(), 13)") MsgBox oQueryResult.GetColumnString(1, 1) |
the value 13 passed as last parameter to the CONVERT() function represents the European standard date format (dd mon yyyy hh:mm:ss:mmmm). For all the possible values, refer to the Books Online. This solution is to be preferred to the direct change of the international settings in the Control Panel followed by setting the RegionalSetting property of the SQLDMO.SQLServer object to True, because it leaves to the application the full control over the display format. |
|