Please start any new threads on our new site at https://forums.sqlteam.com. 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
 time stamp?

Author  Topic 

dlorenc
Posting Yak Master

172 Posts

Posted - 2008-12-10 : 18:33:43
As a greenbean sql guy...the concept of timestamps based on an integer field that counts from 1/1/1970 (?) escapes me...

this code should work, I think...help?

I get this error: Msg 8115, Level 16, State 2, Line 1
Arithmetic overflow error converting expression to data type datetime.

If I remove the WHERE, it works...so there is something I'm missing related to the compare of the interger field 'Create_time' and the ts function???

in one record, for example, create_time = 1184014446



SELECT Actual_End_Date, Actual_Start_Date
, Auto_close_Days
, Auto_close_Time, Auto_End_Time
, Auto_Start_Time
, Category
, Create_Time, Description
, Estimated_Total_Time
, Hours_to_resolve
, IncidentID, HPD_HelpDesk.instanceId
, Modified_Time
, Resolved_Time
, Solution_Description, Solution_Summary
, Status
, Time_Spent__min_, Total_Time_Spent


FROM HPD_HelpDesk
WHERE (Create_Time>={ts '2008-09-01 00:00:00'})

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-12-10 : 18:47:01
Here's what I used in the past: http://weblogs.sqlteam.com/tarad/archive/2003/11/10/473.aspx

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

dlorenc
Posting Yak Master

172 Posts

Posted - 2008-12-11 : 09:44:06
mmm..I use sql mgmt studio, have read-only access to the database...how might I utilize a udf?
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-12-11 : 10:05:32
just run this and see if you've some invalid dates


select * from HPD_HelpDesk
WHERE ISDATE(Create_Time)=0
OR (ISDATE(Create_Time)=1 AND LEN(Create_Time)<8)


and correct the invalid values
Go to Top of Page

dlorenc
Posting Yak Master

172 Posts

Posted - 2008-12-11 : 10:13:38
no invalid dates...but I did some surfing..and found a note on conversion using dateadd...

dateadd(s,Create_Time,'19700101')as Createdate

converts my integer in create_time, to a date...so my where looks like:

WHERE (dateadd(s,Create_Time,'19700101')>={ts '2008-09-01 00:00:00'})and
(dateadd(s,Create_Time,'19700101')<{ts '2008-10-01 00:00:00'})

to pull records for the month of september...does this make sense?
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-12-11 : 10:28:42
shouldnty it be dateadd(s,Create_Time,'19000101') rather than dateadd(s,Create_Time,'19700101')?
Go to Top of Page

dlorenc
Posting Yak Master

172 Posts

Posted - 2008-12-11 : 11:13:43
everything I read talks about 1/1/1970 being the magic timestamp date...established by unix...I think..

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=66858

http://en.wikipedia.org/wiki/Unix_time

Go to Top of Page

dlorenc
Posting Yak Master

172 Posts

Posted - 2008-12-11 : 11:16:22
maybe it depends on the database architecture to pick that magic date..but that particular conversion, works with my database...my dates seem to convert into reasonable date for my helpdesk application (ie. I do get 9/1/2008-9/30/2008 records...if I changed to 1/1/1900, I expect I would get some weird dates..mm?...

and I do..the dates convert to 1937...
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-12-11 : 15:58:42
It's definitely 1970 when you are talking about Java.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page
   

- Advertisement -