THWACK logo
THWACK
  • Sign In
  • Search
  • Community
    Community

    Find all you need to begin your THWACK journey, including documentation, missions, blogs, community groups, events, and media.

    Command Central
    • Getting Started
    MVP Program
    • MVP Program
    Monthly Mission
    • Hidden Gems
    Blogs
    • Community Announcements
    • Product Blog
    Groups
    • DevOps Discourse
    • Data Driven
    • See All Groups
    Events
    • SolarWinds User Group
    • THWACKcamp
      • ↪ 2024: On Demand
    • Bracket Battle
    Media Vault
    • Movies & Mainframes
    • TechPod
    • THWACK Tech Tips
    • THWACK Livecast
    • SolarWinds Lab Archive
    • THWACKcamp Archive
    • See All Media
  • Products
    Products

    Find the best place to learn and ask questions about your SolarWinds products.

    Observability
    • Observability Solutions
    • SolarWinds Observability SaaS
    • SolarWinds Observability Self-Hosted
    • SolarWinds Platform
    Network Management
    • Network Performance Monitoring
    • NetFlow Traffic Analyzer
    • Network Configuration Manager
    • IP Address Manager
    • User Device Tracker
    • VoIP & Network Quality Manager
    • Log Analyzer
    • Engineer's Toolset
    • Network Topology Mapper
    • Kiwi CatTools
    • Kiwi Syslog Server
    • ipMonitor
    Application Management
    • AppOptics
    • Loggly
    • Papertrail
    • Pingdom
    • DevOps
    IT Security
    • Access Rights Manager
    • Identity Monitor
    • Security Event Manager
    • Patch Manager
    • Serv-U FTP & MFT
    IT Service Management
    • SolarWinds Service Desk
    • Web Help Desk
    • DameWare Remote Support
    • DameWare Remote Everywhere
    • DameWare Mini Remote Control
    System Management
    • Server & Application Monitor
    • Virtualization Manager
    • Storage Resource Monitor
    • Server Configuration Monitor
    • SolarWinds Backup
    • Web Performance Monitor
    Database Management
    • Database Performance Analyzer
    • SQL Sentry
    • Database Performance Monitor
    • Database Mapper
    • Task Factory
  • Content Exchange
    Content Exchange

    Find downloadable files and templates other users have built and found useful to share with others.

    SolarWinds Platform
    • Alerts
    • Custom HTML
    • Custom Queries
    • Modern Dashboards
    • Reports
    • Scripts
    Server & Application Monitor
    • API Pollers
    • Application Monitor Templates
    Database Performance Analyzer
    • Custom Alerts
    • Custom Metrics
    • Custom Queries
    Server Configuration Monitor
    • Policies
    • Profiles
    Network Performance Monitor
    • Device Pollers
    • Universal Device Pollers
    Network Configuration Manager
    • Config Change Scripts
    • Device Templates
    • Firmware Upgrade Templates
    • Policy Documents
    SQL Sentry
    • Advisory Conditions
    Web Help Desk
    • Style Sheets
  • Resources
    SolarWinds Customer Portal Customer Portal

    Create individual user accounts for your team, manage your licenses, download your SolarWinds software, create and track support tickets, and more.

    SolarWinds Academy Academy

    A one-stop-shop for world-class training for SolarWinds products through on-demand videos, and instructor-led classes. All SolarWinds Academy content is included with every software purchase.

    SolarWinds Customer Success Support

    Get help when you need it from a world-class support team, available to assist with technical product issues 24 hours a day, seven days a week, 365 days a year.

    SolarWinds Partner Portal Partner Portal

    Accelerate SolarWinds Partners’ ability to drive digital and IT transformation for customers with powerful tools, resources, and increased profit potential.

  • Free Tools & Trials
  • Store
The SolarWinds Platform
  • Products
The SolarWinds Platform
SolarWinds Platform API Working with Dates
  • Newsroom
  • Forums
  • SolarWinds Platform API
  • Content Exchange
  • What We're Working On
  • Feature Requests
  • More
  • Cancel
  • New
  • -SolarWinds Platform API
    • About the SolarWinds Information Service (SWIS)
    • +Setting up a Python Development Environment
    • +Using PowerShell 7+ and Visual Studio Code
    • +SolarWinds Query Language (SWQL) Basics
    • -Data Presentation Examples
      • Enhancing Custom Query Widgets
      • Poor Man's PIVOT
      • Potential Gotchas
      • Returning the Most Recent Element from a Related Entity
      • Working with Dates
    • Additional Resources
    • Glossary

Working with Dates

Dates are frequently an issue when you are dealing with large data sets.  Most often used for timespans to limit or group reporting, working with dates can more difficult than other datatypes.  Date spans like the examples provided below are most often used for summarization of historical data to look for trends, outliers, or anomalies.  We THWACKsters frequently get asked for assistance in building these date spans, so we felt it made sense to collect the most common requests in one area.

Assumptions: We are assuming all dates are stored in the ObservationTimestamp property and are stored in the UTC time zone.

Examples of Common Date Spans

Current UTC Date/Time Description WHERE Clause Range Start Range End
2023-03-15 11:33:00 Last 15 minutes [ObservationTimestamp] >= ADDMINUTE( -15, GETUTCDATE() ) 2023-03-15 11:18:00
2023-03-15 11:33:00 Last 1 hour [ObservationTimestamp] >= ADDHOUR( -1, GETUTCDATE() ) 2023-03-15 10:33:00
2023-03-15 11:33:00 Last 1 day [ObservationTimestamp] >= ADDDAY( -1, GETUTCDATE() ) 2023-03-14 11:33:00
2023-03-15 11:33:00 Last 1 week [ObservationTimestamp] >= ADDWEEK( -1, GETUTCDATE() ) 2023-03-06 11:33:00
2023-03-15 11:33:00 Last 1 month [ObservationTimestamp] >= ADDMONTH( -1, GETUTCDATE() ) 2023-02-15 11:33:00
2023-03-15 11:33:00 Last 1 year [ObservationTimestamp] >= ADDYEAR( -1, GETUTCDATE() ) 2022-03-15 11:33:00
2023-03-15 11:33:00 Today [ObservationTimestamp] >= DATETRUNC('day', GETUTCDATE() ) 2023-03-15 00:00:00
2023-03-15 11:33:00 Yesterday [ObservationTimestamp] BETWEEN DATETRUNC('day', ADDDAY(-1, GETUTCDATE() ) ) AND DATETRUNC('day', GETUTCDATE() ) 2023-03-14 00:00:00 2023-03-15 00:00:00
2023-03-15 11:33:00 This week [ObservationTimestamp] >= DATETRUNC('week', GETUTCDATE() ) 2023-03-12 11:33:00
2023-03-15 11:33:00 Last week [ObservationTimestamp] BETWEEN DATETRUNC('week', ADDWEEK(-1, GETUTCDATE() ) ) AND DATETRUNC('week', GETUTCDATE() ) 2023-03-15 00:00:00 2023-03-12 00:00:00
2023-03-15 11:33:00 This month [ObservationTimestamp] >= DATETRUNC('month', GETUTCDATE() ) 2023-03-01 00:00:00
2023-03-15 11:33:00 Last month [ObservationTimestamp] BETWEEN DATETRUNC('month', ADDMONTH(-1, GETUTCDATE() ) ) AND DATETRUNC('month', GETUTCDATE() ) 2023-02-01 00:00:00 2023-03-01 00:00:00
2023-03-15 11:33:00 This quarter [ObservationTimestamp] >= DATETRUNC('quarter', GETUTCDATE() ) 2023-01-01 00:00:00
2023-03-15 11:33:00 Last quarter [ObservationTimestamp] BETWEEN DATETRUNC('quarter', ADDQUARTER-1, GETUTCDATE() ) ) AND DATETRUNC('quarter', GETUTCDATE() ) 2023-01-01 00:00:00 2023-03-01 00:00:00
2023-03-15 11:33:00 This year [ObservationTimestamp] >= DATETRUNC('year', GETUTCDATE() ) 2023-01-01 00:00:00
2023-03-15 11:33:00 Last year [ObservationTimestamp] BETWEEN DATETRUNC('year', ADDYEAR(-1, GETUTCDATE() ) ) AND DATETRUNC('year', GETUTCDATE() ) 2022-01-01 00:00:00 2023-01-01 00:00:00

Summarizing Date-bound Information

One of the best functions for summarizing among date/time spans is DOWNSAMPLE.

Suppose we want the CPU load for all of my nodes for the last 24 hours (1 day).  We would start with a query to bring in all the information.

SELECT [Nodes].Caption
     , [Nodes].CPULoadHistory.AvgLoad
     , [Nodes].CPULoadHistory.ObservationTimestamp
FROM Orion.Nodes AS [Nodes]
-- Only show me information for the last 24 hours (1 day)
WHERE [Nodes].CPULoadHistory.ObservationTimestamp >= ADDDAY(-1, GETUTCDATE())

-- Returns 1,706 rows in a very small lab

Even in a small lab environment, this will return many thousands of records.  What we really want is a summarization (average) of these values for each hour of the day.

SELECT [Nodes].Caption
     , AVG([Nodes].CPULoadHistory.AvgLoad) AS [AvgLoad]
     , DOWNSAMPLE([Nodes].CPULoadHistory.ObservationTimestamp, '01:00:00') AS [HourOfDay]
FROM Orion.Nodes AS [Nodes]
-- Only show me information for the last 24 hours (1 day)
WHERE [Nodes].CPULoadHistory.ObservationTimestamp >= ADDDAY(-1, GETUTCDATE())
GROUP BY [Nodes].Caption
       , DOWNSAMPLE([Nodes].CPULoadHistory.ObservationTimestamp, '01:00:00')
--
-- Returns 295 records
--

This returns significantly fewer rows but still provides us with the data we need.

The DOWNSAMPLE function can work with any aggregation function (average, sum, count, min, max).

  • Timespans
  • dates
  • date/time
  • Share
  • History
  • More
  • Cancel
Related
Recommended

SolarWinds solutions are rooted in our deep connection to our user base in the THWACK® online community. More than 200,000 members are here to solve problems, share technology and best practices, and directly contribute to our product development process.

SolarWinds Customer Success Center Certification SolarWinds Lab Link Customer Portal
About THWACK SolarWinds Blog Federal & Government Edit Settings Free Tools & Trials
Legal Documents Terms of Use Privacy California Privacy Rights Security Information
©2021 SolarWinds Worldwide, LLC. All Rights Reserved.