Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Is this a bug in the DATEADD function

Posted on 2007-12-04
5
Medium Priority
?
900 Views
Last Modified: 2008-02-01
select top 5 timestamp,dateadd(second,11,timestamp)as SyncDate,event from logtable

returns

timestamp             SyncDate              event                                                                                                                                                                                                                                                            
--------------------- --------------------- -------------------------------------
2007-07-13 13:15:00   2007-07-13 13:15:00   Program Startup
2007-07-13 13:15:00   2007-07-13 13:15:00   CorpXfer database successfully opened
2007-07-13 13:15:00   2007-07-13 13:15:00   Initializing Alarm control...
2007-07-13 13:15:00   2007-07-13 13:15:00   Alarm Control disconnected from Host
2007-07-13 13:15:00   2007-07-13 13:15:00   Alarm Control connected to Host

select top 5 timestamp,dateadd(minute,11,timestamp)as SyncDate,event from logtable

returns

timestamp             SyncDate              event                                                                                                                                                                                                                                                            
--------------------- --------------------- ---------------------------------------------------------
2007-11-29 00:05:00   2007-11-29 00:16:00   059289 Sending C:\CorpXfer\LocalCopy\Accumulators\ACCUMULATORS20071129000500CST.TXT to DoverFTP
2007-11-29 00:05:00   2007-11-29 00:16:00   059289 Successfully connected to DoverFTP
2007-11-29 00:05:00   2007-11-29 00:16:00   Processing 059289 Hourly05 Accumulators
2007-11-29 00:05:00   2007-11-29 00:16:00   5 Minute Analogs for MOST item added to que. Filename = C:\CorpXfer\LocalCopy\5 Minute Analogs (MOST)\ANALOGS20071129000500CST.TXT
2007-11-29 00:05:00   2007-11-29 00:16:00   Hourly05 Analogs item added to que. Filename = C:\CorpXfer\LocalCopy\Analogs\ANALOGS20071129000500CST.TXT

The syntax I am using is obviously correct. Why does the second one correctly add 11 minutes to timestamp while the first does not add 11 seconds to timestamp? I think this is a bug but I can't believe something this simple ever made it into production.

0
Comment
Question by:rjdegraff
[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
5 Comments
 
LVL 17

Accepted Solution

by:
Chris Mangus earned 200 total points
ID: 20403970
If your TIMESTAMP column is a data type of smalldatetime you won't have any seconds stored or used.
0
 
LVL 36

Expert Comment

by:SidFishes
ID: 20403990
this works as expected

select getdate()
select dateadd(second, 11, getdate())

inclined to agree that it's a data formatting issue and not a bug
0
 

Author Comment

by:rjdegraff
ID: 20404038
Hah!

You are correct. I NEVER use SmallDateTime fields, however, this table was created automatically when I imported the data from an Access database. I changed the field to DATETIME and tried again. Success.

Thanks much.
0
 
LVL 5

Expert Comment

by:ursangel
ID: 20410014
I too agree with cmangus reply.
let us know the datatype of your TimeStamp column. If its smalldatetime, then it will not work as u expect.
try this excampl and you can c teh difference. I have declared the @val variable as Datetime and it works perfectly, now you chnage the data type to smalldatetime and c how its behaving.

declare @val ldatetime
set @val = '2007-12-05'
select @val
select dateadd (ss ,10,  @val)
0
 
LVL 17

Expert Comment

by:Chris Mangus
ID: 20423213
Is there anything else we can do for you on this question?
0

Featured Post

Use Filtering Commands to Process Files in Linux

Learn how to manipulate data with the help of various filtering commands such as `cat`, `fmt`, `pr`, and others in Linux.

Question has a verified solution.

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

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
What if you have to shut down the entire Citrix infrastructure for hardware maintenance, software upgrades or "the unknown"? I developed this plan for "the unknown" and hope that it helps you as well. This article explains how to properly shut down …
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

721 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