Site sponsored by: Idera Try Idera’s new SQL admin toolset
SQL Server Performance

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


Article Topics

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

SQL Server 2008 - Worth the Wait

SQL Server’s first significant upgrade in three years features a number of envelope-pushing enhancements and improvements. Which will have the greatest impact on SQL administration and development? More...
Latest Articles

Slowly Changing Dimensions in SQL Server 2005
Audit Data Modifications
SQL Server 2008’s Management Data Warehouse
Same Report but Different Methods in SQL Server Reporting Services ...

More     
 
Latest FAQ's

How to Integrate Performance Monitor and SQL Profiler
SSIS Lookups are Case Sensitive
Convert Number to Words in SSRS
After installing SP2 on SQL Server 2005 x64, when trying to ...

More     
   
Latest Software Reviews

SQL Server DBA Dashboard
SwisSQL DBChangeManager
SQLMesh - SQL Server Search Tool
SoftTreeTech SQL Assistant

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
Printer friendly

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








Home | Peformance Articles | Audit Articles | Business Intelligence Articles | Clustering Articles | Developer Articles | Reporting Services Articles | DBA Articles | ASP.NET / ADO.NET Articles | 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 | QDPMA Performance Tuning | 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