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)
 converting date

Author  Topic 

js.reddy
Yak Posting Veteran

80 Posts

Posted - 2007-11-16 : 07:01:46
Hi All!

I have following table column

JoiningDate
-----------------------
2007-11-16 17:23:34.030
2007-11-15 17:24:13.297
2007-11-14 17:24:18.110
2007-11-13 17:24:23.810


I want convert the above column to the following format
Can any one help me
Thanks

JoiningDate
-----------------------
2007-11-16 00:00:00.000
2007-11-15 00:00:00.000
2007-11-14 00:00:00.000
2007-11-13 00:00:00.000

hitman
Starting Member

23 Posts

Posted - 2007-11-16 : 07:32:00
maybe you can use datepart & dateadd combination

declare @new_date datime
set @new_date = '2007-11-13 17:24:23.810'

set @new_date = dateadd(hh, - datepart(hh, @new_date), @new_date)
set @new_date = dateadd(mi, - datepart(mi, @new_date), @new_date)
set @new_date = dateadd(ss, - datepart(ss, @new_date), @new_date)
set @new_date = dateadd(ms, - datepart(ms, @new_datet), @new_date)

-----------------------
http://www.sqltips.info
-----------------------
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2007-11-16 : 07:36:35
SELECT DATEADD(d, DATEDIFF(d, 0, GetDate()), 0)


_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
SSMS Add-in that does a few things: www.ssmstoolspack.com
Go to Top of Page

hitman
Starting Member

23 Posts

Posted - 2007-11-16 : 07:38:39
this is better :-)

-----------------------
http://www.sqltips.info
-----------------------
Go to Top of Page

js.reddy
Yak Posting Veteran

80 Posts

Posted - 2007-11-16 : 07:39:36
Thanks


quote:
Originally posted by spirit1

SELECT DATEADD(d, DATEDIFF(d, 0, GetDate()), 0)


_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
SSMS Add-in that does a few things: www.ssmstoolspack.com

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-11-19 : 02:18:23
quote:
Originally posted by spirit1

SELECT DATEADD(d, DATEDIFF(d, 0, GetDate()), 0)


_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
SSMS Add-in that does a few things: www.ssmstoolspack.com


Just for clarity I prefer using day in place of d

SELECT DATEADD(day, DATEDIFF(day, 0, GetDate()), 0)

Madhivanan

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

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2007-11-19 : 03:32:38
i prefer to type less

_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
SSMS Add-in that does a few things: www.ssmstoolspack.com
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-11-19 : 09:11:01
I prefer not to type. Just click copy and click paste


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2007-11-19 : 12:13:56
Can also be done with CAST & CONVERT

CAST(CONVERT(varchar(11),GETDATE()) AS datetime)
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-11-19 : 13:44:17
quote:
Originally posted by visakh16

Can also be done with CAST & CONVERT

CAST(CONVERT(varchar(11),GETDATE()) AS datetime)


but the dateadd / datediff method is fastest


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-11-20 : 01:37:27
quote:
Originally posted by visakh16

Can also be done with CAST & CONVERT

CAST(CONVERT(varchar(11),GETDATE()) AS datetime)


There are N number of methods in fact

Madhivanan

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

- Advertisement -