Atlanta Custom Software Development 

 
   Search        Code/Page
 

User Login
Email

Password

 

Forgot the Password?
Services
» Web Development
» Maintenance
» Data Integration/BI
» Information Management
Programming
  Database
Automation
OS/Networking
Graphics
Links
Tools
» Regular Expr Tester
» Free Tools

Manage the SQL Server date format with SQL DMO

Total Hit ( 3152)

Rate this article:     Poor     Excellent 

 Submit Your Question/Comment about this article

Rating


 


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.


Submitted By : Nayan Patel  (Member Since : 5/26/2004 12:23:06 PM)

Job Description : He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting.
View all (893) submissions by this author  (Birth Date : 7/14/1981 )


Home   |  Comment   |  Contact Us   |  Privacy Policy   |  Terms & Conditions   |  BlogsZappySys

© 2008 BinaryWorld LLC. All rights reserved.