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
 datediff with unixtimestamp
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

aliyesami
Starting Member

USA
30 Posts

Posted - 11/29/2012 :  15:32:52  Show Profile  Reply with Quote
I have a table with date in unix timestamp and iam using the following query to get the dates which are older than 10 mins but its giving me error :

Select class, workstation from ALERTS where active='Y' and datediff(minute, created, getdate()) > 10;

Msg 8115, Level 16, State 2, Line 2
Arithmetic overflow error converting expression to data type datetime.

sunitabeck
Flowing Fount of Yak Knowledge

5155 Posts

Posted - 11/29/2012 :  15:40:24  Show Profile  Reply with Quote
Change it to
Select class, workstation from ALERTS 
where active='Y' and datediff(minute, DATEADD(ss,created,'19700101'), getdate()) > 10;
Go to Top of Page

jimf
Flowing Fount of Yak Knowledge

USA
2869 Posts

Posted - 11/29/2012 :  15:42:22  Show Profile  Reply with Quote
You know a lot of weird things, Sunita.


Jim

Everyday I learn something that somebody else already knew
Go to Top of Page

sunitabeck
Flowing Fount of Yak Knowledge

5155 Posts

Posted - 11/29/2012 :  15:45:45  Show Profile  Reply with Quote
Not my fault Jim! I work with a few quants who use unix and perl and epoch time and everything in between. They polluted me.
Go to Top of Page

robvolk
Most Valuable Yak

USA
15663 Posts

Posted - 11/29/2012 :  15:52:48  Show Profile  Visit robvolk's Homepage  Reply with Quote
Variation that may perform better:
Select class, workstation from ALERTS 
where active='Y' and created < DATEDIFF(second, '1/1/1970', dateadd(minute, -10, getdate()))
If "created" is indexed this can do a seek instead of a scan.
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.08 seconds. Powered By: Snitz Forums 2000