Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: SS7,SS2K
Expertise: Intermediate
May 5, 2001

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.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.

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

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

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

Giuseppe Dimauro
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date