Solved

Is this a bug in the DATEADD function

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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

860 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