Apr 17, 2007

SQL: Getting Only the Date Part of a Date/Time Stamp in SQL Server

Using SQL 2005
methode 1:

CAST((
STR( YEAR( GETDATE() ) ) + '/' +
STR( MONTH( GETDATE() ) ) + '/' +
STR( DAY( GETDATE() ) ))
AS DATETIME)

methode 2(I think the beter one):

CAST(
FLOOR( CAST( GETDATE() AS FLOAT ) )
AS DATETIME)

No comments: