SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Date Part
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Sean_B
Posting Yak Master

United Kingdom
111 Posts

Posted - 06/27/2007 :  03:31:50  Show Profile  Reply with Quote
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

India
22772 Posts

Posted - 06/27/2007 :  03:48:36  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
What is wrong with option 1?
Thats the way to go

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000