Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Date Part

Author  Topic 

Sean_B
Posting Yak Master

111 Posts

Posted - 2007-06-27 : 03:31:50
Hi Guys,

I realise this is probably a well discussed topic but
recently a colleague asked me about getting only the date part of a date for doing a comparison in a query.

He'd used the following code

SELECT left(DATEADD(day,-1,getdate()),11)

to compare the date parts

I've seen various methods of doing this like
---------1
select dateadd(day, datediff(day, 0, getdate()), 0)

which is what I tend to use
---------2
SELECT
CAST(
(
STR( YEAR( GETDATE() ) ) + '/' +
STR( MONTH( GETDATE() ) ) + '/' +
STR( DAY( GETDATE() ) )
)
AS DATETIME
)
---------3
select
CAST(
FLOOR
( CAST
( GETDATE() AS FLOAT )
) AS DATETIME
)
---------

I was wondering which is the best way of doing this ?

Is there a generally accepted way ?

Or doesn't it matter ?



Sean

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-06-27 : 03:48:36
What is wrong with option 1?
Thats the way to go

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -