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)
 How to extract time from datetime?

Author  Topic 

azamsharp
Posting Yak Master

201 Posts

Posted - 2008-06-02 : 15:48:31
How can I extract time from 2007-04-05 18:25:47.603?



Mohammad Azam
www.azamsharp.net

azamsharp
Posting Yak Master

201 Posts

Posted - 2008-06-02 : 16:24:34
Here is the code that I got from the web:

dateadd(day, datediff(day, 0, ti.begintime) * -1, ti.begintime) >= @starttime

Mohammad Azam
www.azamsharp.net
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-06-03 : 00:36:40
quote:
Originally posted by azamsharp

How can I extract time from 2007-04-05 18:25:47.603?



Mohammad Azam
www.azamsharp.net


you need to use CONVERT function for this. But its always better to do this at front end if its just for display purpose.
Go to Top of Page

pk_bohra
Master Smack Fu Yak Hacker

1182 Posts

Posted - 2008-06-03 : 08:13:04
Try this:

SELECT convert(varchar,cast('2007-04-05 18:25:47.603' AS datetime) ,114)

In case the field is datetime and not varchar( as some programmer store even datetime value in varchar ) then you can try this.

SELECT convert(varchar, <Substitute field name >,114)
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-06-03 : 08:49:37
Shorter and cleaner to read would for example be
SELECT	dateadd(day, datediff(day, @f, 0), @f)
Even shorter is
SELECT	@f - datediff(day, 0, @f)



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page
   

- Advertisement -