Solved

Add Milliseconds to Datetime

Posted on 2006-11-02
2
2,111 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

In this article—a derivative of my DaytaBase.org blog post (http://daytabase.org/2011/06/18/what-week-is-it/)—I will explore a few different perspectives on which week today's date falls within using Microsoft SQL Server. First, to frame this stu…
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…
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

743 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now