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.
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 butrecently 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 codeSELECT left(DATEADD(day,-1,getdate()),11)to compare the date parts I've seen various methods of doing this like---------1select dateadd(day, datediff(day, 0, getdate()), 0)which is what I tend to use---------2SELECT CAST(( STR( YEAR( GETDATE() ) ) + '/' + STR( MONTH( GETDATE() ) ) + '/' + STR( DAY( GETDATE() ) ))AS DATETIME )---------3selectCAST( 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 goMadhivananFailing to plan is Planning to fail |
|
|
|
|
|