Solved

DATEADD Off By An Hour

Posted on 2014-09-18
4
188 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 32

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

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Join & Write a Comment

In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

760 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

16 Experts available now in Live!

Get 1:1 Help Now