Solved

DATEADD Off By An Hour

Posted on 2014-09-18
4
191 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:
Kdo 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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Long way back, we had to take help from third party tools in order to encrypt and decrypt data.  Gradually Microsoft understood the need for this feature and started to implement it by building functionality into SQL Server. Finally, with SQL 2008, …
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

813 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now