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

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

Share the Post:
Heading photo, Metadata.

What is Metadata?

What is metadata? Well, It’s an odd concept to wrap your head around. Metadata is essentially the secondary layer of data that tracks details about the “regular” data. The regular

XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved

AI is revolutionizing fraud detection

How AI is Revolutionizing Fraud Detection

Artificial intelligence – commonly known as AI – means a form of technology with multiple uses. As a result, it has become extremely valuable to a number of businesses across

AI innovation

Companies Leading AI Innovation in 2023

Artificial intelligence (AI) has been transforming industries and revolutionizing business operations. AI’s potential to enhance efficiency and productivity has become crucial to many businesses. As we move into 2023, several

data fivetran pricing

Fivetran Pricing Explained

One of the biggest trends of the 21st century is the massive surge in analytics. Analytics is the process of utilizing data to drive future decision-making. With so much of

kubernetes logging

Kubernetes Logging: What You Need to Know

Kubernetes from Google is one of the most popular open-source and free container management solutions made to make managing and deploying applications easier. It has a solid architecture that makes