SQL 2000 exchange link server time is wrong

Posted on 2006-05-10
Medium Priority
Last Modified: 2008-01-09
I have sql server 2000 running on my exchange box so that I can run query's on some people's email box for a customer managment system. I have the mailboxes attached as linked servers and run the following query to make a view.

SELECT     *
FROM         OPENQUERY(Stacy,
"urn:schemas:mailheader:date" AS DateSent,
"urn:schemas:mailheader:To" AS MailheaderTo,
"urn:schemas:httpmail:to" AS To,
"urn:schemas:mailheader:from" AS FROM,
"urn:schemas:mailheader:subject" AS Subject,
"urn:schemas:httpmail:datereceived" AS DateReceived,
"urn:schemas:httpmail:fromemail" AS FromEmail,
"urn:schemas:httpmail:fromname" AS FromName,
"urn:schemas:httpmail:textdescription" AS Body,
"urn:schemas:httpmail:htmldescription" AS HTML,
"urn:schemas:mailheader:message-id" as ID
FROM Inbox
WHERE "urn:schemas:httpmail:fromemail" IS NOT NULL')

My problem is that the DateSent is in the future by about 6 hours. The time on the exchange server is correct, so why is the date in the database hours ahead of where it should be?

Question by:poulsborv
  • 3
  • 3
LVL 17

Expert Comment

by:Chris Mangus
ID: 16653948
I'll bet your timezone is GMT-6 (CST / MDT), isn't it?  Email servers typically store email with a datetime stamp that corresponds to GMT time.  You're going to have to account for that in your query.

Author Comment

ID: 16653973
Do you mean in SQL or on the server itself? The server is set to GMT Pacific time like it should be... checking the sql server

Author Comment

ID: 16653986
Where do I check it in the sql server?
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 17

Expert Comment

by:Chris Mangus
ID: 16654055
Well that's interesting! :)  I would have assumed you were in CST / MDT time zone.  Since you're in GMT Pacific Time zone is would expect your query to be showing DateSent as your local time + 7 hours, not 6.

When I query my exchange servers I get GMT from mailheader:date and I have to subtract 7 hours because I am in MST.  This is because email is stored with a datetime stamp corresponding to GMT time when it was sent.  This is all regardless of how the time zone is set on your exchange server.  When Outlook displays the email it will take into account your time zone and display a date time that is GMT + or - your time zone.

There is no setting of time in SQL Server.  When you run the GetDate() function it will return the current system time.
LVL 17

Accepted Solution

Chris Mangus earned 1500 total points
ID: 16654104
Check this link.


It very briefly describes some time zone issues and also talks about how urn:schemas:calendar:timezoneid can be used to determine what time zone your exchange server really think's it's in.

Author Comment

ID: 16654185
Well I fudged it a little bit and stopped using the sent date from the exchange server. When I run the query now, which I do every 5 minutes I just date it with now() so that I am with in 5 minutes of when they actually sent it. Thanks for your help cmanqus.

Featured Post

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

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

One of the most important things in an application is the query performance. This article intends to give you good tips to improve the performance of your queries.
Creating a Cordova application which allow user to save to/load from his Dropbox account the application database.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

864 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