Solved

DATEADD Off By An Hour

Posted on 2014-09-18
4
192 Views
Last Modified: 2014-09-19
Hello:

One of the fields I have in a report is based on the following T-SQL query:

DATEADD(s,({*Document_tb:TimeCreated} + (3600*-5)),'1/1/1970')

The customer is saying that the resulting "Time Created" is off by an hour.  Specifically, this field displayed as 2:24 PM, when it should have displayed as 3:24 PM.

The customer is in the Eastern Time Zone.  It is possible, too, that this field is not changing with the Daylight Savings Time change occurring in the spring.  

Anyway, to manually fix this, do I change the -5 to a different number such as -4 or -6?

TBSupport
0
Comment
Question by:TBSupport
4 Comments
 
LVL 45

Accepted Solution

by:
Kent Olsen earned 500 total points
ID: 40331539
Hi TBSupport,

It looks like the code is converting from GMT to EST.  

Change -5 to -4.

And note that this kind of conversion may have other issues down the line....
0
 
LVL 33

Expert Comment

by:ste5an
ID: 40331542
First of all: get rid of the unnecessary calculus. Use DATEADD(HOUR,{},'') instead. Your time created value must be an integer value. So when this is a time value, then the problem maybe the implicit conversion from your time value to INT. Maybe DATEADD(HOUR, -5, {}) is sufficient.
0
 
LVL 69

Expert Comment

by:Scott Pletcher
ID: 40331630
>> It is possible, too, that this field is not changing with the Daylight Savings Time change occurring in the spring. <<

I strongly suspect that's it.  Nasty, because then you need a table for DST so you can tell if the setting is different now vs. when the document was created.  But I think you'll need that to accurately translate these times.
0
 
LVL 48

Expert Comment

by:PortletPaul
ID: 40331947
Appears that the field value is a Unix timestamp (expressed as seconds from 1970-01-01) hence the arithmetic requiring 3600*-5 :: and I don't believe there is an implicit conversion, just adding seconds to a date.

alternate: put time out with EST as suffix (i.e. don't attempt daylight saving conformance)

i.e.
this field displays as 2:24 PM EST

(and it won't display 3:24 PM ESST)

----
or whatever your summer time TZ abbreviation is
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL 2008 R2 syntax 11 36
Linked Server Issue with SQL2012 3 28
SQL Server 2008 R2, need a pivot/cross tab query... 4 29
What is this datetime? 1 20
by Mark Wills Attending one of Rob Farley's seminars the other day, I heard the phrase "The Accidental DBA" and fell in love with it. It got me thinking about the plight of the newcomer to SQL Server...  So if you are the accidental DBA, or, simp…
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

829 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