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)
 smalldatetime to milliseconds

Author  Topic 

Ambikaa
Starting Member

43 Posts

Posted - 2009-02-22 : 06:35:28
Hi,

I need to convert smalldatetime datatype column to milliseconds?
original data
BeginTime
1899-12-30 01:00:00.000
1899-12-30 19:00:00.000
1899-12-30 20:00:00.000
1899-12-30 20:15:00.000
1899-12-30 19:10:00.000
through this query i got this o/p

SELECT CONVERT(VARCHAR(8), begintime, 108)from demo3

Begin Time
01:00:00
19:00:00
20:00:00
20:15:00
19:10:00

but, i need only milliseconds
how can i achieve it?

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2009-02-22 : 08:46:03
[code]SELECT Substring(Right(Convert(varchar(40),getdate(),109),5),1,3)[/code]
Go to Top of Page

raky
Aged Yak Warrior

767 Posts

Posted - 2009-02-24 : 01:57:01
No need to convert.Just use this

select datepart (ms,begintime ) as 'MilliSeconds' from demo3
Go to Top of Page

Ambikaa
Starting Member

43 Posts

Posted - 2009-02-24 : 02:10:51
quote:
Originally posted by raky

No need to convert.Just use this

select datepart (ms,begintime ) as 'MilliSeconds' from demo3



It shows only zero value.
Go to Top of Page

bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2009-02-24 : 02:23:12
see this ambikaa,
in ur data there is only zero for milliseconds
check this query once
select getdate(),datepart (ms,getdate() ) as 'MilliSeconds'
Go to Top of Page

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2009-02-24 : 04:00:23
Ambikaa, in your original posting, you said the datatype is smalldatetime. If that is true, then your millisecond part will always be zero. This is because smalldatetime precision is only to the minute. Use datetime rather than smalldatetime and you will get precision to milliseconds (actually to 3.333 milliseconds precision)
Go to Top of Page
   

- Advertisement -