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
 Transact-SQL (2000)
 getdate() issue

Author  Topic 

sqllearner
Aged Yak Warrior

639 Posts

Posted - 2005-09-08 : 22:48:54
When I ran this query select getdate().It gave me this value :-
2005-09-08 19:45:54.280

How can I convert the above date to something like shown below

2005-09-08 00:00:00.000

ryanston
Microsoft SQL Server Product Team

89 Posts

Posted - 2005-09-08 : 23:50:28
Are you just trying to get the date from the datetime? Take a look at DATEPART if so. Otherwise, can you be a bit more detailed in what you're trying to do?

Thanks,

----------------------
Ryan Stonecipher
Developer, Microsoft SQL Server Storage Engine, DBCC
(Legalese: This posting is provided "AS IS" with no warranties, and confers no rights.)
Go to Top of Page

sqllearner
Aged Yak Warrior

639 Posts

Posted - 2005-09-09 : 00:59:07
I want the value to be 2005-09-08 00:00:00.000 so that i can the events that happend for the day at any point of time by checking the date > 2005-09-08 00:00:00.000
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-09-09 : 01:00:22

SELECT DateAdd(d, DateDiff(d, 0, getdate()), 0)

Madhivanan

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

venkatsrv
Starting Member

2 Posts

Posted - 2005-09-09 : 02:06:34
SELECT cast(convert(varchar,getdate(),101) as datetime)
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-09-09 : 02:15:09
Venkat, yours use two conversions whereas mine use no conversions
Although it is alternate solution, avoid using Conversions

Madhivanan

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

Kristen
Test

22859 Posts

Posted - 2005-09-09 : 04:24:19
"SELECT cast(convert(varchar,getdate(),101) as datetime)"

Only works on a server configured for USA date format

I posted a comparison of performance a while back - if you are interested! The CONVERT/CAST method is abou 3 - 5 times slower than the one with no conversions.

http://www.sqlteam.com/Forums/topic.asp?TOPIC_ID=38940

Kristen
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-09-09 : 04:38:32
Thats good point Kris

Madhivanan

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

VladRUS.ca
Starting Member

23 Posts

Posted - 2005-09-09 : 10:27:25
One more variant:
set dateformat ymd
select {fn current_date()}
Go to Top of Page
   

- Advertisement -