Solved

Add Milliseconds to Datetime

Posted on 2006-11-02
2
2,115 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
2 Comments
 
LVL 11

Accepted Solution

by:
rw3admin earned 250 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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

When you hear the word proxy, you may become apprehensive. This article will help you to understand Proxy and when it is useful. Let's talk Proxy for SQL Server. (Not in terms of Internet access.) Typically, you'll run into this type of problem w…
Having an SQL database can be a big investment for a small company. Hardware, setup and of course, the price of software all add up to a big bill that some companies may not be able to absorb.  Luckily, there is a free version SQL Express, but does …
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

770 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