This discussion has been locked. The information referenced herein may be inaccurate due to age, software updates, or external references.
You can no longer post new replies to this discussion. If you have a similar question you can start a new discussion in this forum.

how to change the time in an SQL report

I am using the following sql query that I got off of the thwack site to report on which nodes are in a unmanaged mode. The time is off by 5 hours. Solarwinds tech support says that the reason is that I am in Central Standard time GMT-5, and the sql tables are in UTC time. Can some "sql report writer guru" help me with this. The following is the query that I am using. The query works fine, but again the times are wrong. If I input 8:00 AM, this query will show 1:00 PM.

SELECT
Nodes.Caption, Nodes.UnmanageFrom, Nodes.UnmanageUntil, Nodes.StatusDescription
FROM
Nodes
where
Unmanaged = 1 or unmanagefrom >= getdate()
ORDER
BY 1 ASC, 2 DESC

  • This isn't all that pretty, but try: Nodes.Caption, DateAdd(Hour,DATEDIFF(Hour,GETUTCDATE(),GETDATE()),Nodes.UnmanageFrom) as UnmanageFrom, DateAdd(Hour,DATEDIFF(Hour,GETUTCDATE(),GETDATE()),Nodes.UnmanageUntil) as UnmanageUntil, Nodes.StatusDescription

  • You can simply use GETUTCDATE() instead of GETDATE() in your condition:

    SELECT

    Nodes.Caption, Nodes.UnmanageFrom, Nodes.UnmanageUntil, Nodes.StatusDescription

    FROM

    Nodes

    where

    Unmanaged = 1 or unmanagefrom >= getUTCdate()

    ORDER

    BY 1 ASC, 2 DESC

  • I had already tried using both getutcdate() and getdate() and they both give the UTC date.

  • Oh, I was focused on condition where incorrect comparison of UTC (unmanagedfrom) and local (getdate()) times was used. If you want to have output recalculated to local time, then netlogix's part of query is what you need. I would just change hour interval to minute because there are timezones with half hour timeshift... So final query could look like this:

    SELECT

        Nodes.Caption,

        DateAdd(MINUTE,DATEDIFF(MINUTE,GETUTCDATE(),GETDATE()),Nodes.UnmanageFrom) as UnmanageFromLocal,

        DateAdd(MINUTE,DATEDIFF(MINUTE,GETUTCDATE(),GETDATE()),Nodes.UnmanageUntil) as UnmanageUntilLocal,

        Nodes.StatusDescription

    FROM

    Nodes

    where

    Unmanaged = 1 or unmanagefrom >= getutcdate()

    ORDER

    BY 1 ASC, 2 DESC

  • That worked. Thank you for your help, and also thanks to netlogix for pointing in the right direction. I greatly appreciate it, as I do not have any sql report writing skills. You guys are GREAT!