Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

DATEADD Off By An Hour

Posted on 2014-09-18
4
Medium Priority
?
203 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 46

Accepted Solution

by:
Kent Olsen earned 2000 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 36

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 70

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 49

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

SQL Server engine let you use a Windows account or a SQL Server account to connect to a SQL Server instance. This can be configured immediatly during the SQL Server installation or after in the Server Authentication section in the Server properties …
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Loops Section Overview

963 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