?
Solved

Add Milliseconds to Datetime

Posted on 2006-11-02
2
Medium Priority
?
2,123 Views
Last Modified: 2008-12-26
I have an external system that will be calling my SP with a datetime value, and with a milliseconds value that I want to add to that datetime value as I insert it into my database.

Currently, I have this, which does not add the 2 values together.  Can someone help me with whatever CAST or CONVERT call I need to make in order to add these 2 values together either just before or as I insert the timestamp into the table?

Thanks very much.
===========================================
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go

ALTER PROCEDURE [dbo].[spInsertEvent]
   @TransactionTimestamp datetime = NULL,
   @TransactionMilliseconds int = NULL,
   @DatapointName varchar(64) = NULL,
   @EventValue int = NULL
AS
BEGIN
   INSERT INTO Events
      (TransactionTimestamp, DatapointName, EventValue)
      VALUES
      (@TransactionTimestamp + @TransactionMilliseconds, @DatapointName, @EventValue)

   DECLARE @return_value int
   SET @return_value = 0
END
GO
0
Comment
Question by:bryker
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 11

Accepted Solution

by:
rw3admin earned 1000 total points
ID: 17862725
ALTER PROCEDURE [dbo].[spInsertEvent]
   @TransactionTimestamp datetime = NULL,
   @TransactionMilliseconds int = NULL,
   @DatapointName varchar(64) = NULL,
   @EventValue int = NULL
AS
BEGIN
   INSERT INTO Events
      (TransactionTimestamp, DatapointName, EventValue)
      VALUES
      (DateAdd(ms,@TransactionMilliseconds, @TransactionTimestamp ), @DatapointName, @EventValue)

   DECLARE @return_value int
   SET @return_value = 0
END
0
 
LVL 4

Expert Comment

by:Makolyte
ID: 23245928
Why does it round if i'm putting DATEADD(ms, 999, @date), it's rounding UP to the next second, which doesn't help
0

Featured Post

10 Questions to Ask when Buying Backup Software

Choosing the right backup solution for your organization can be a daunting task. To make the selection process easier, ask solution providers these 10 key questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Viewers will learn how the fundamental information of how to create a table.
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question