Article ID: 186265 - View products that this article applies to.
This article was previously published under Q186265
You can use the SQL Server DATEPART() function to get the milliseconds of a SQL Server datetime field returned to a Visual Basic application.
The advantage of using the SQL Server DATEPART() function is that it is simple to use and works with all versions of ADO, DAO, and RDO. The disadvantage of using the DATEPART() function is that it is specific to SQL Server. However, other servers may have comparable functions.
Do not confuse the SQL Server DATEPART() function with the Visual Basic DatePart() function, which is used with the Visual Basic Date datatype.
The SQL Server DATEPART() function returns a portion of a SQL Server datetime field.
The syntax of the SQL Server DATEPART() function is:
where datetime is name of a SQL Server datetime field and portion is one of the following:
Ms for Milliseconds Yy for Year Qq for Quarter of the Year Mm for Month Dy for the Day of the Year Dd for Day of the Month Wk for Week Dw for the Day of the Week Hh for Hour Mi for Minute Ss for Second
Use the SQL Server DATEPART() function in a Transact-SQL (T-SQL) SELECT statement. An example T-SQL statement using DATEPART() follows:
This would return Pubdate and the millisecond portion of Pubdate.
Sample CodeThe following example uses the ActiveX Data Objects (ADO) 1.5 library. The same T-SQL statement would work with the DAO and RDO libraries also.
For more information on the SQL Server DATEPART() function, look in the SQL Server Books Online. Click Transact-SQL Reference, F, Functions, Date Functions.
Article ID: 186265 - Last Review: March 14, 2005 - Revision: 2.3