SQL Server Performance

  • Home
  • Articles
  • Forums
  • Tips
  • Training
  • FAQ's
  • Blogs
  • Software
  • Books
  • About Us
RSS Feeds
Sign in | Join


Article Topics

All Articles
Performance Tuning
Audit
Business Intelligence
Clustering
Reporting Services
SQL Azure
Developer
General DBA
ASP.NET / ADO.NET
SQL Azure

USEFUL SITES :

ASP.NET Tutorials
Windows and SQL Azure Tutorials
Cloud Hosting Magazine
SharePoint Tutorials
Windows Server Help

Write for Us

Share your SQL Server knowledge with others and raise your profile in the community More...
Latest Articles

A High Level Comparison Between Oracle and SQL Server - Part ...
A High Level Comparison Between Oracle and SQL Server - Part ...
A High Level Comparison Between Oracle and SQL Server - Part ...
A High Level Comparison Between Oracle and SQL Server

More     
 
Latest FAQ's

Add Node to A SQL Server failover Cluster failed with invalid ...
SQL Server Destination remote server error
Setting Up Data And Log Files For SQL Server
Will Check Constraints Improve Database Performance?

More     
   
Latest Software Reviews

dbForge Review
Spotlight on ApexSQL Diff - Server-based database comparison tool ...
Spotlight on ApexSQL Data Diff - Server-based database comparison tool ...
Spotlight on ApexSQL Doc 2008

More     

articles >> developer >> How to Fix the Problem When ADO ...

How to Fix the Problem When ADO Truncates Milliseconds from SQL Server Datetime Columns

By : Brian Lockwood
Jul 20, 2002

If you create a SQL Server table that contains a datetime column and populate it with a GetDate() default then try to query it with ADO, you will discover that the data returned from datetime columns is returned without milliseconds. If you need milliseconds returned, this can be very annoying to deal with.

For example, in VB:

strSQL = "SELECT DateTime FROM DateTest"

objRs.Open strSQL

? objRs(o)

8/9/2002 11:15:27 PM

But if you perform the query within Query Analyzer, you get the true result:

2002-08-09 23:15:27.490

 

SOLUTION 1 - Do it in Transact-SQL

If you know the query you are going to execute in VB, you can manipulate the SQL string to add the necessary formatting. There are three groups of date formats in SQL Server you can use to to preserve milliseconds

  • 9 or 109 for Default + milliseconds
  • 13 or 113 for Europian format
  • 21 or 121 for ODBC format (that also matches ISO format)

For example,

SELECT CONVERT(varchar, DateTime, 21) FROM DateTest

Returns:

2002-08-09 23:15:27.490

But this solution might not be possible for all situations. Another alternative is to do it in Visual Basic itself.

 

SOLUTION 2 - Use FormatDateTime Function?

VB provides the FormatDateTime Function, which accepts the VBLongTime constant:

vbLongTime = Displays a time using the time format specified in your computer's regional settings.

For example:

? FormatDateTime(now(), vbLongTime)

11:41:54 AM

Returns:

But again, this does not return milliseconds. I have attempted to configure my regional settings (via the Control Panel) to allow for milliseconds, but: 1) I ran into the same problem as above, and 2) this would create a dependancy on your user's desktop settings for your program to work -- which is not good.


    Next Page>>    








C# Help and Tutorials | PHP MySQL Tutorial | Sharepoint Tutorial | Azure Tutorial | Cloud Hosting Magazine | ASP.NET Tutorials | Windows Server Help | Windows Phone Pro | Silverlight Ace | Visual Studio Tutorials | Home | Peformance Articles | Audit Articles | Business Intelligence Articles | Clustering Articles | Developer Articles | Reporting Services Articles | DBA Articles | ASP.NET / ADO.NET Articles | SQL Server Training Videos | DBA FAQ's | Developer Peformance FAQ's | DBA Peformance FAQ's | Developer FAQ's | Clustering FAQ's | Error Messages | Audit Tool Reviews | Backup Tool Reviews | Coding Tool Reviews | Compare Tool Reviews | Documentation Tool Reviews | Design Tool Reviews | Monitoring Tool Reviews | Log Tool Reviews | Reporting Tool Reviews | Clustering Tool Reviews | Security Tool Reviews | Change Management Tool Reviews | Remote Access Tool Reviews | Book Reviews | Security Tool Reviews | ADO.NET / ASP.NET | Administration | Analysis/OLAP Services | Application Development | Configuration | Components | ETL | Hardware | High Availability | Hints | Index | Misc | Operating Systems | Performance Tuning | Replication | T-SQL | Views


              © 2010 Jude O'Kelly. All rights reserved