Welcome to EMC Consulting Blogs Sign in | Join | Help

Merrick Chaffer's Blog

SQL 2008 Date part extraction from DATETIME

SQL 2008 introduces the new DATE data type, and it is considerable quicker to CAST a DATETIME to this if you’re attempting to just extract the date part from a DATETIME field, than using the old method of

SELECT CONVERT(DATETIME,CONVERT(CHAR,GETUTCDATE(),102))

So from SQL 2008 onwards this can now be written as

SELECT CAST(GETUTCDATE() AS DATE)

Published 06 October 2010 12:08 by merrick.chaffer

Comments

 

jamie.thomson said:

Wouldn't it be nice if they had datatypes for time precisions other than day/minute/millisecond/nanosecond? Yes it would, hence:

[T-SQL] Month & Quarter datatype

(https://connect.microsoft.com/SQLServer/feedback/details/521145/t-sql-month-quarter-datatype)

October 6, 2010 12:28
Anonymous comments are disabled

This Blog

Syndication

News

Powered by Community Server (Personal Edition), by Telligent Systems