devxlogo

Manage the SQL Server date format with SQL DMO

Manage the SQL Server date format with SQL DMO

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:

Dim oSQLServer As SQLDMO.SQLServerDim oQueryResult As SQLDMO.QueryResultsSet oSQLServer = New SQLDMO.SQLServeroSQLServer.LoginTimeout = 15oSQLServer.ODBCPrefix = FalseoSQLServer.Connect "MySQLServer", "sa", vbNullStringSet 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.

########################################################

This tip has been originally published on Microsoft Italia’s web site.
It has been translated and re-published on VB2TheMax with the permission of Microsoft Italia.
You can find more tips like this one (in Italian) at http://www.microsoft.com/italy/sql/articoli

########################################################

devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist