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
 General SQL Server Forums
 New to SQL Server Programming
 datetime value

Author  Topic 

cwtriguns2002
Constraint Violating Yak Guru

272 Posts

Posted - 2008-02-04 : 22:33:01
hi everyone...
i have a question on datetime value.
How could I replace the time value to '00:00:00'?

for example, i have a datetime value of '2008-02-05 11:24:03.030'
my expected result is '2008-02-05 00:00:00'


RON
________________________________________________________________________________________________
"I won't last a day without SQL"




hey001us
Posting Yak Master

185 Posts

Posted - 2008-02-04 : 22:41:15
CAST(LEFT('2008-02-05 11:24:03.030', 11) AS datetime)

hey
Go to Top of Page

hey001us
Posting Yak Master

185 Posts

Posted - 2008-02-04 : 22:49:53
OR DATEADD(dd,DATEDIFF(dd, 0,'2008-02-05 11:24:03.030'),0)

hey
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-02-04 : 22:53:04
or CAST(CONVERT(varchar(11),'2008-02-05 11:24:03.030') AS datetime)
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-02-05 : 08:00:36
quote:
Originally posted by visakh16

or CAST(CONVERT(varchar(11),'2008-02-05 11:24:03.030') AS datetime)


Effecient method is

Dateadd(day,datediff(day,0,datecol),0)

Madhivanan

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

- Advertisement -