HOWTO: Using SQL DMO to Print Date in Regional FormatID: Q220918
|
This article demonstrates how to use two different methods using SQL Distributed Management Objects (DMO) to return dates formatted to a specific regional locale.
By default, the date format for SQL server is in U.S. date format MM/DD/YY, unless a localized version of SQL Server has been installed. The SET DATEFORMAT statement and sp_addlanguage will not change the display format for dates.
Here are two ways to resolve this issue:
Dim oSQLServer As SQLDMO.SQLServer
Set oSQLServer = New SQLDMO.SQLServer
oSQLServer.LoginTimeout = 15
'oSQLServer.ODBCPrefix = False
Dim oQueryResult As Object
oSQLServer.Connect "<my70Server>", "<Uid>"
Set oQueryResult = oSQLServer.ExecuteWithResults("SELECT
CONVERT(char(12), GETDATE(), 13)")
Debug.Print oQueryResult.GetColumnString(1, 1)
The last parameter in the Convert() function is to apply Style 13, which is the European default (dd mon yyyy hh:mm:ss:mmm) of the date format.
Dim oSQLServer As SQLDMO.SQLServer
Set oSQLServer = New SQLDMO.SQLServer
oSQLServer.LoginTimeout = 15
oSQLServer.ODBCPrefix = False
Dim oQueryResult As Object
oSQLServer.Connect "<mySQL7Server>", "<Uid>"
oSQLServer.RegionalSetting = True
Debug.Print oSQLServer.Databases(1).Tables(1).CreateDate
The CreateDate method will print in English(United Kingdom) date format.SQL Server 7.0 Books Online, topic: "SQL-DMO"
Additional query words: kbDSupport
Keywords : kbDatabase kbOLEDB kbSQLServ kbVC kbSQLServ700
Version : winnt:7.0
Platform : winnt
Issue type : kbhowto
Last Reviewed: May 10, 1999