Solved

Is this a bug in the DATEADD function

Posted on 2007-12-04
5
896 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 50 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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

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.
It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
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 to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

623 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