SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


convert date object into integer


convert date object into integer

Author
Message
j nuñez
j nuñez
Ten Centuries
Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)

Group: General Forum Members
Points: 1145 Visits: 279
I continue without understand what you need exactly.

Anyway, to obtain the number of miliseconds from a datetime value, you can use something like this:

declare @Date DATETIME

SET @Date = convert(datetime, '2009-09-01 09:30:15.927')


SELECT convert(BIGINT, @Date)* 86400000

SELECT DATEPART(hh, @Date) * 3600000
SELECT DATEPART(mi, @Date) * 60000
SELECT DATEPART(ss, @Date) * 1000
SELECT DATEPART(ms, @Date)


SELECT (convert(BIGINT, @Date)* 86400000 ) + (DATEPART(hh, @Date) * 3600000) + (DATEPART(mi, @Date) * 60000) + (DATEPART(ss, @Date) * 1000) + DATEPART(ms, @Date)


And, the final result is:

Datetime: 2009-09-01 09:30:15.925
Number of milisenconds: 3460786215927


I hope this can help you.
jacob sebastian
jacob sebastian
Ten Centuries
Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)

Group: General Forum Members
Points: 1042 Visits: 2523
If it is a matter of finding the difference between two dates (in milliseconds) you can even run the following query.

DECLARE @d1 DATETIME, @d2 DATETIME
SELECT @d1 = '1/9/2008 11:30:24.123', @d2 = '1/10/2008'

SELECT DATEDIFF(millisecond, @d1, @d2) AS Diff
/*
Diff
-----------
44975877
*/



Or you can extract specific information from the date value using the following query and apply your required calculations.

DECLARE @d1 DATETIME, @d2 DATETIME
SELECT @d1 = '1/9/2008 11:30:24.123'

SELECT
DATEPART(year, @d1) AS Years,
DATEPART(month, @d1) AS Months,
DATEPART(day, @d1) AS Days,
DATEPART(hour, @d1) AS Hours,
DATEPART(minute, @d1) AS Minutes,
DATEPART(second, @d1) AS Seconds,
DATEPART(Millisecond, @d1) AS Milliseconds

/*
Years Months Days Hours Minutes Seconds Milliseconds
----------- ----------- ----------- ----------- ----------- ----------- ------------
2008 1 9 11 30 24 123
*/



.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search