Solved

DATEADD Off By An Hour

Posted on 2014-09-18
4
189 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:ScottPletcher
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL Help - 12 59
Storage Spaces 3 37
Advice in using ms sql data types as in INT and BIGINT, also as in NUMERIC DECIMAL MONEY 2 47
Sql query 107 22
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, …
Naughty Me. While I was changing the database name from DB1 to DB_PROD1 (yep it's not real database name ^v^), I changed the database name and notified my application fellows that I did it. They turn on the application, and everything is working. A …
A short film showing how OnPage and Connectwise integration works.
This is a video that shows how the OnPage alerts system integrates into ConnectWise, how a trigger is set, how a page is sent via the trigger, and how the SENT, DELIVERED, READ & REPLIED receipts get entered into the internal tab of the ConnectWise …

932 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

15 Experts available now in Live!

Get 1:1 Help Now