SQL 2000 exchange link server time is wrong

Posted on 2006-05-10
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
    LVL 17

    Expert Comment

    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

    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

    Where do I check it in the sql server?
    LVL 17

    Expert Comment

    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

    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

    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

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    Join & Write a Comment

    Introduction: I have seen many questions on EE and elsewhere, asking about how to find either gaps in lists of numbers (id field, usually) ranges of values or dates overlapping date ranges combined date ranges I thought it would be a good …
    I annotated my article on ransomware somewhat extensively, but I keep adding new references and wanted to put a link to the reference library.  Despite all the reference tools I have on hand, it was not easy to find a way to do this easily. I finall…
    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…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    746 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

    18 Experts available now in Live!

    Get 1:1 Help Now