Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Add Milliseconds to Datetime

Posted on 2006-11-02
2
Medium Priority
?
2,125 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

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

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

Ready to get certified? Check out some courses that help you prepare for third-party exams.
This month, Experts Exchange sat down with resident SQL expert, Jim Horn, for an in-depth look into the makings of a successful career in SQL.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

636 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