April 13, 2006 at 7:09 am
I need to apply the logic below in a sp on SQL Server 2000. I not sure how to code this. Can anyone give me some help? Thanks
(DateOfInterest - 1/1/1970 03:00) *24 *60 *60 *1000 = n
April 13, 2006 at 8:01 am
note that the number of milliseconds will overflow an int value, so you've got to use a bigint datatype:
declare @DateOfInterest datetime,
@EpochDate datetime,
@millisecs bigint
set @DateOfInterest = '12/11/1962'
set @EpochDate = '1/1/1970 03:00'
--select (@DateOfInterest - @EpochDate) *24 *60 *60 *1000 as n
--causes overflow if you try and get milliseconds, because the function returns an INT:
--select @millisecs=datediff(ms,@DateOfInterest,@EpochDate)
select datediff(ss,@DateOfInterest,@EpochDate)
select @millisecs=datediff(ss,@DateOfInterest,@EpochDate)
--convert to milliseconds
set @millisecs = @millisecs * 1000
select @millisecs as [numOfMilliseconds]
Lowell
April 13, 2006 at 11:21 pm
Thanks for your help!
April 17, 2006 at 9:38 pm
Or... don't let it default to INT...
declare @DateOfInterest datetime,
@EpochDate datetime
set @DateOfInterest = '12/11/1962'
set @EpochDate = '1/1/1970 03:00'
select CAST((@DateOfInterest - @EpochDate) AS DECIMAL(24)) *24 *60 *60 *1000 as n
--Jeff Moden
Change is inevitable... Change for the better is not.
April 17, 2006 at 10:45 pm
Both worked great. Thanks for your help!
April 18, 2006 at 8:43 pm
...and thank you for the feedback...
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply