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 2005 Forums
 Transact-SQL (2005)
 Datetime conversion

Author  Topic 

sanjnep
Posting Yak Master

191 Posts

Posted - 2007-10-31 : 13:06:37
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
Master Smack Fu Yak Hacker

2507 Posts

Posted - 2007-10-31 : 13:09:30
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

216 Posts

Posted - 2007-10-31 : 13:09:50
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

191 Posts

Posted - 2007-10-31 : 13:29:49
Thanks a lot.........
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-11-01 : 02:35:48
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 - 2007-11-02 : 02:19:21
try this also

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

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-11-02 : 03:03:35
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
   

- Advertisement -