SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 DATEADD function
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

revdnrdy
Posting Yak Master

USA
220 Posts

Posted - 01/07/2009 :  18:13:11  Show Profile  Reply with Quote
Hello..

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..

r&r

tkizer
Almighty SQL Goddess

USA
36983 Posts

Posted - 01/07/2009 :  18:15:24  Show Profile  Visit tkizer's Homepage  Reply with Quote
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
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

USA
7020 Posts

Posted - 01/07/2009 :  18:29:26  Show Profile  Reply with Quote
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:

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


Results:
DT
-------------------------
2044-10-13 01:19:02.000




CODO ERGO SUM
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000