Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Is this a bug in the DATEADD function

Posted on 2007-12-04
5
Medium Priority
?
906 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 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
Windocks is an independent port of Docker's open source to Windows.   This article introduces the use of SQL Server in containers, with integrated support of SQL Server database cloning.
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.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

927 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