Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 DATEADD function

Author  Topic 

Posting Yak Master

220 Posts

Posted - 2009-01-07 : 18:13:11

This is a question about DATEADD function.
This is from sql server 2005

Why does the first sql statement return an error? They are identical sans the unix timestamp..

select dateadd(ss,2359934342,'01/01/1970')
result: Arithmetic overflow error converting expression to data type int.

But this one returns a date as expected
select dateadd(ss,1078576968,'01/01/1970')
result: 2004-03-06 12:42:48.000

thanks for any feedback..


Almighty SQL Goddess

38200 Posts

Posted - 2009-01-07 : 18:15:24
Try converting the 235 value to a bigint, not sure if dateadd can accept a bigint. I haven't tested of course.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server

Subscribe to my blog
Go to Top of Page

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2009-01-07 : 18:29:26
The error message you got tells you exactly what the problem is:
you cannot convert the number 2359934342 to a datatype of integer.

The largest possible value for datatype integer is 2147483647.

This code should do what you want:

DT =dateadd(ss,a.x%86400,dateadd(dd,a.x/86400,'19700101'))
( select x = convert(bigint,2359934342) ) a

2044-10-13 01:19:02.000

Go to Top of Page

- Advertisement -