|
Sean_B
Posting Yak Master
United Kingdom
111 Posts |
Posted - 06/27/2007 : 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 |
|