time-filtering
This skill contains shell command directives (!`command`) that may execute system commands. Review carefully before installing.
TD Time Filtering - Advanced Patterns
td_interval Offset Date Syntax
Reference date can be absolute, relative, or now:
-- Absolute reference date
where td_interval(time, '-1d/2025-10-01') -- Yesterday relative to Oct 1
where td_interval(time, '-7d/2025-10-01', 'JST')
-- Relative reference date
where td_interval(time, '-1d/-7d') -- Yesterday relative to 7 days ago
where td_interval(time, '-7d/-1d') -- Last 7 days from yesterday
-- now keyword
where td_interval(time, '-1d/now') -- Yesterday until now
where td_interval(time, '0d/now') -- Beginning of today until now
where td_interval(time, '0M/now') -- Beginning of this month until now
where td_interval(time, '0y/now') -- Beginning of this year until now
-- Combined patterns
where td_interval(time, '-7d/0M') -- Last 7 days from month start
where td_interval(time, '0M/-7d') -- This month up to 7 days ago
Interval Units
s=seconds, m=minutes, h=hours, d=days, w=weeks, M=months, q=quarters, y=years
td_interval_range for Debugging
select td_interval_range('-7d', 'UTC') -- Returns [start, end] timestamps
select td_interval_range('-1d/2025-10-01', 'JST') -- Check offset date range
select td_interval_range('0M/now', 'JST') -- Verify month-to-date range
td_time_string for Display
select td_time_string(time, 'd!') -- 2025-01-15 (UTC)
select td_time_string(time, 'd!', 'JST') -- 2025-01-15 (JST)
select td_time_string(time, 'M!', 'JST') -- 2025-01
select td_time_string(time, 'h!', 'JST') -- 2025-01-15 10
Codes: y! q! M! w! d! h! m! s!. Timezone optional (defaults to UTC). Use for display/grouping only, not filtering.
td_scheduled_time Reference
In workflows, include td_scheduled_time() to establish reference time:
select td_scheduled_time(), *
from mydb.events
where td_interval(time, '-1d', 'JST')
Partition Pruning Gotchas
-- BAD: Functions on time prevent pruning
where date(from_unixtime(time)) = '2025-01-15'
-- GOOD: Use td_time_range
where td_time_range(time, '2025-01-15', '2025-01-16')
-- BAD: Raw timestamp comparison
where time > 1704067200
-- GOOD: Use td_interval
where td_interval(time, '-7d')
-- BAD: Different column
where created_at > current_date - interval '7' day
-- GOOD: Use time column
where td_interval(time, '-7d')
Troubleshooting Empty Results
-- Check data range
select min(time), max(time) from mydb.events
-- Try different timezones
select count(*) from mydb.events where td_interval(time, '-1d') -- UTC
select count(*) from mydb.events where td_interval(time, '-1d', 'JST') -- JST
Resources
More from treasure-data/td-skills
pytd
Expert assistance for using pytd (Python SDK) to query and import data with Treasure Data. Use this skill when users need help with Python-based data analysis, querying Presto/Hive, importing pandas DataFrames, bulk data uploads, or integrating TD with Python analytical workflows.
20tdx-basic
Executes tdx CLI commands for Treasure Data. Covers `tdx databases`, `tdx tables`, `tdx describe`, `tdx query`, `tdx auth setup`, context management with profiles/sessions, and output formats (JSON/TSV/table). Use when users need tdx command syntax, authentication setup, database/table exploration, schema inspection, or query execution.
3workflow
Manages TD workflows using `tdx wf` commands. Covers project sync (pull/push/clone), running workflows, monitoring sessions/attempts, task timeline visualization, retry/kill operations, and secrets management. Use when users need to manage, monitor, or debug Treasure Workflow projects via tdx CLI.
3journey
Load when the client wants to create, edit, or manage a CDP customer journey. Use for building journey YAML with segments, activations, and stage steps, modifying journey stages or flow logic (decision points, condition waits, A/B tests), or pushing journey changes to Treasure Data. Also load when the client wants to analyze journey performance, query journey tables, create journey dashboards, or generate journey action reports.
2parent-segment-analysis
Query and analyze CDP parent segment database data. Use `tdx ps desc -o` to get output database schema, then query customers and behavior tables. Use when exploring parent segment data, building reports, or analyzing customer attributes and behaviors.
2connector-config
Writes connector_config for segment/journey activations using `tdx connection schema <type>` to discover available fields. Use when configuring activations - always run schema command first to see connector-specific fields.
2