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 2005 Forums
 Transact-SQL (2005)
 Datetime conversion
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

sanjnep
Posting Yak Master

USA
175 Posts

Posted - 10/31/2007 :  13:06:37  Show Profile  Visit sanjnep's Homepage  Reply with Quote
I have date value
2005-11-29 11:24:08.443 on one table and I want this format
2005-11-29 00:00:00.000 to insert another table on datetime column. How can I do this?

Thanks
Sanjeev

dinakar
Flowing Fount of Yak Knowledge

USA
2347 Posts

Posted - 10/31/2007 :  13:09:30  Show Profile  Visit dinakar's Homepage  Reply with Quote
DATEADD(d,0,DATEDIFF(d,0,YourDatetimeColumn))

Dinakar Nethi
************************
Life is short. Enjoy it.
************************
http://weblogs.sqlteam.com/dinakar/
Go to Top of Page

sshelper
Posting Yak Master

196 Posts

Posted - 10/31/2007 :  13:09:50  Show Profile  Visit sshelper's Homepage  Reply with Quote
To remove the time part in you DATETIME column, you can do the following:

SELECT DATEADD(DD, DATEDIFF(DD, 0, '2005-11-29 11:24:08.443'), 0)

SQL Server Helper
http://www.sql-server-helper.com
Go to Top of Page

sanjnep
Posting Yak Master

USA
175 Posts

Posted - 10/31/2007 :  13:29:49  Show Profile  Visit sanjnep's Homepage  Reply with Quote
Thanks a lot.........
Go to Top of Page

madhivanan
Premature Yak Congratulator

India
20644 Posts

Posted - 11/01/2007 :  02:35:48  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
I prefer using day instead of D or DD for more clarity

More infor on querying dates
www.sql-server-performance.com/fk_datetime.asp

Madhivanan

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

ranganath
Posting Yak Master

209 Posts

Posted - 11/02/2007 :  02:19:21  Show Profile  Reply with Quote
try this also

Select cast(convert (varchar(12), getdate(),101) as Datetime )
Go to Top of Page

madhivanan
Premature Yak Congratulator

India
20644 Posts

Posted - 11/02/2007 :  03:03:35  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
quote:
Originally posted by ranganath

try this also

Select cast(convert (varchar(12), getdate(),101) as Datetime )


You dont need double convertions. Read previous replies

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 Version 3.4.03