Solved

getdate to get proper date

Posted on 2007-12-06
9
860 Views
Last Modified: 2008-02-01
I have a server which is located in the eastern time zone and all of my clients are in the atlantic time zone.  when i put in getdate() it gets the eastern date.  i need to be able to get the atlantic date.  is there a command which will show you the date/time where you are at?
0
Comment
Question by:Fraser_Admin
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +2
9 Comments
 
LVL 75

Expert Comment

by:Aneesh Retnakaran
ID: 20419775
Not in sql server 2000/2005; you can get the GMT by using GETUTCDate()
0
 

Expert Comment

by:OFGemini
ID: 20419859
Use
CONVERT ( data_type [ ( length ) ] , expression [ , style ] )
function to get the result according to your format
Last parameter is about the required format
Get help in your T-SQL Help on Convert Function and look for the avaible formats.
0
 
LVL 92

Expert Comment

by:Patrick Matthews
ID: 20419930
Hello Fraser_Admin,

*If* your clients use the same DST rules as you, then you could use:

SELECT DATEADD(h, -1, GETDATE()) AS TimeInAtlanticZone

That will work except for when you get within an hour of the change-over from standard time to
daylight time, and vice versa.

Regards,

Patrick
0
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 

Author Comment

by:Fraser_Admin
ID: 20420403
that is what i ended up doing, but now we may have another client coming on board in the eastern time zone, so i somehow need to find out what time zone they are in so i can display the proper date for them.
0
 
LVL 15

Expert Comment

by:dbbishop
ID: 20420585
I would suggest either using aneeshattingal's solution of using UTC, or pass the date/time from the client application to the server.
Is it possible to add another column to your table (TZO-Time Zone Offset)? In your client app (assuming VB, but can be done in most languages), code something like:

Dim tzo As Integer = DateDiff(DateInterval.Hour, DateTime.UtcNow, dateTime.Now)

And pass tzo to SQL Server. That way, you can use GETUTCDate() in SQL Server to store the time, and store tzo. That way, you can ALWAYS get the current local time by adding tzo to the datetime.
0
 
LVL 15

Expert Comment

by:dbbishop
ID: 20420601
The good thing about the solution I present is that it will work for ANY time zone the client is in, Eastern, Central, Pacific, Hawaiian, or another country.
0
 
LVL 92

Expert Comment

by:Patrick Matthews
ID: 20420652
Fraser_Admin,

With the possibility of supporting multiple time zones, my simplistic suggestion no longer
merits consideration.  The other Experts are on a better track.

Regards,

Patrick
0
 

Author Comment

by:Fraser_Admin
ID: 20420688
yea i will have to put some thought into this.  the big thing i was looking for is say you have a user who is in one time zone and a user in another time zone and they are both running the same report.  i would like it to show them the current date in their time zone, not the time zone the server is sitting in.  maybe i will somehow have to assign time zones to a user and work that way.  just thought sqlserver could figure that out for you.
0
 
LVL 15

Accepted Solution

by:
dbbishop earned 500 total points
ID: 20421076
SQL Server has no way of knowing what time zone you are in. Doing as I suggest (storing UTC and a time zone offest) is probably your best solution.

The good thing about this type of solution is, if I usually work out of the EST zone, but travel to a PST office and do some work there, you have not tied the user to a specific time zone.
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
query analyser in sql server 2016 express edition 2 26
SQL Select Query help 1 38
A question about syntax 5 25
Estimating my database size 7 13
Nowadays, some of developer are too much worried about data. Who is using data, who is updating it etc. etc. Because, data is more costlier in term of money and information. So security of data is focusing concern in days. Lets' understand the Au…
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

749 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