Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

feat(data-table): add absolute/relative time toggle to column header menu (#57872)

Steven Shultsaa8adc61fe27
diff --git a/frontend/src/queries/nodes/DataTable/DataTable.tsx b/frontend/src/queries/nodes/DataTable/DataTable.tsx
index 08132f8dd9bb..3c762d2370f2 100644
--- a/frontend/src/queries/nodes/DataTable/DataTable.tsx
+++ b/frontend/src/queries/nodes/DataTable/DataTable.tsx
@@ -37,7 +37,7 @@ import { DataTableSavedFiltersButton } from '~/queries/nodes/DataTable/DataTable
import { EventRowActions } from '~/queries/nodes/DataTable/EventRowActions'
import { InsightActorsQueryOptions } from '~/queries/nodes/DataTable/InsightActorsQueryOptions'
import { QueryFeature } from '~/queries/nodes/DataTable/queryFeatures'
-import { getContextColumn, renderColumn } from '~/queries/nodes/DataTable/renderColumn'
+import { DATETIME_KEYS, getContextColumn, renderColumn } from '~/queries/nodes/DataTable/renderColumn'
import { renderColumnMeta } from '~/queries/nodes/DataTable/renderColumnMeta'
import { SavedQueries } from '~/queries/nodes/DataTable/SavedQueries'
import { TableViewSelector } from '~/queries/nodes/DataTable/TableView/TableViewSelector'
@@ -337,6 +337,24 @@ export function DataTable({
<div className="font-mono truncate">{removeExpressionComment(key)}</div>
)}
</div>
+ {(isEventsQuery(query.source) || isActorsQuery(query.source)) &&
+ DATETIME_KEYS.includes(removeExpressionComment(key)) ? (
+ <>
+ <LemonDivider />
+ <LemonButton
+ fullWidth
+ data-attr="datatable-toggle-absolute-time"
+ onClick={() => {
+ setQuery?.({
+ ...query,
+ showAbsoluteTime: !query.showAbsoluteTime,
+ })
+ }}
+ >
+ {query.showAbsoluteTime ? 'Show relative time' : 'Show absolute time'}
+ </LemonButton>
+ </>
+ ) : null}
{columnFeatures.includes(ColumnFeature.canEdit) && (
<>
<LemonDivider />
diff --git a/frontend/src/queries/nodes/DataTable/dataTableLogic.ts b/frontend/src/queries/nodes/DataTable/dataTableLogic.ts
index 05b19c6077f2..3e39ca5c05e8 100644
--- a/frontend/src/queries/nodes/DataTable/dataTableLogic.ts
+++ b/frontend/src/queries/nodes/DataTable/dataTableLogic.ts
@@ -238,6 +238,7 @@ export const dataTableLogic = kea<dataTableLogicType>([
showSavedQueries: query.showSavedQueries ?? false,
showSavedFilters: query.showSavedFilters ?? false,
showTableViews: query.showTableViews ?? false,
+ showAbsoluteTime: query.showAbsoluteTime ?? false,
showHogQLEditor: query.showHogQLEditor ?? showIfFull,
allowSorting: query.allowSorting ?? true,
showOpenEditorButton:
diff --git a/frontend/src/queries/nodes/DataTable/renderColumn.tsx b/frontend/src/queries/nodes/DataTable/renderColumn.tsx
index db7c3d4e5634..dba8716f14c8 100644
--- a/frontend/src/queries/nodes/DataTable/renderColumn.tsx
+++ b/frontend/src/queries/nodes/DataTable/renderColumn.tsx
@@ -47,7 +47,7 @@ import { llmAnalyticsColumnRenderers } from 'products/llm_analytics/frontend/llm
import { extractExpressionComment, removeExpressionComment } from './utils'
-const DATETIME_KEYS = ['timestamp', 'created_at', 'last_seen', 'last_seen_at', 'session_start', 'session_end']
+export const DATETIME_KEYS = ['timestamp', 'created_at', 'last_seen', 'last_seen_at', 'session_start', 'session_end']
// Registry for product-specific column renderers
// Products can add their custom column renderers here to have them automatically applied across all DataTable instances
@@ -169,7 +169,13 @@ export function renderColumn(
// do nothing
}
if (value.match(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{3,6})?(?:Z|[+-]\d{2}:\d{2})?$/)) {
- return <TZLabel time={value} showSeconds />
+ return (
+ <TZLabel
+ time={value}
+ showSeconds
+ timestampStyle={query.showAbsoluteTime ? 'absolute' : 'relative'}
+ />
+ )
}
}
if (typeof value === 'object') {
@@ -203,15 +209,18 @@ export function renderColumn(
)
} else if ((isActorsQuery(query.source) || isActorsQuery(query)) && key === 'last_seen_at') {
const isWithinLastHour = dayjs().diff(dayjs(value), 'hour', true) < 1
+ // Hide the "last hour" pill when the absolute-time mode is on — TZLabel's children
+ // override the formatted text, so the pill would otherwise mask the absolute timestamp.
+ const showLastHourPill = isWithinLastHour && !query.showAbsoluteTime
return (
- <TZLabel time={value} showSeconds>
- {isWithinLastHour ? (
+ <TZLabel time={value} showSeconds timestampStyle={query.showAbsoluteTime ? 'absolute' : 'relative'}>
+ {showLastHourPill ? (
<span className="whitespace-nowrap align-middle border-dotted border-b">last hour</span>
) : undefined}
</TZLabel>
)
} else if (DATETIME_KEYS.includes(key)) {
- return <TZLabel time={value} showSeconds />
+ return <TZLabel time={value} showSeconds timestampStyle={query.showAbsoluteTime ? 'absolute' : 'relative'} />
} else if (!Array.isArray(record) && key.startsWith('properties.')) {
// TODO: remove after removing the old events table
const propertyKey = trimQuotes(key.substring('properties.'.length))
diff --git a/frontend/src/queries/schema.json b/frontend/src/queries/schema.json
index 7e3468537a40..07f3b3c305a8 100644
--- a/frontend/src/queries/schema.json
+++ b/frontend/src/queries/schema.json
@@ -12788,6 +12788,10 @@
}
]
},
+ "showAbsoluteTime": {
+ "description": "Render date-time columns (timestamp, created_at, last_seen, last_seen_at, session_start, session_end) as absolute date+time instead of relative (\"X ago\"). The toggle is exposed in the column header menu only on EventsQuery / ActorsQuery sources.",
+ "type": "boolean"
+ },
"showActions": {
"description": "Show the kebab menu at the end of the row",
"type": "boolean"
@@ -34092,6 +34096,10 @@
"shortId": {
"$ref": "#/definitions/InsightShortId"
},
+ "showAbsoluteTime": {
+ "description": "Render date-time columns (timestamp, created_at, last_seen, last_seen_at, session_start, session_end) as absolute date+time instead of relative (\"X ago\"). The toggle is exposed in the column header menu only on EventsQuery / ActorsQuery sources.",
+ "type": "boolean"
+ },
"showActions": {
"description": "Show the kebab menu at the end of the row",
"type": "boolean"
diff --git a/frontend/src/queries/schema/schema-general.ts b/frontend/src/queries/schema/schema-general.ts
index 8ec1e4ec54d9..72e02e6779ed 100644
--- a/frontend/src/queries/schema/schema-general.ts
+++ b/frontend/src/queries/schema/schema-general.ts
@@ -1239,6 +1239,10 @@ interface DataTableNodeViewProps {
showSavedFilters?: boolean
/** Show table views feature for this table (requires uniqueKey) */
showTableViews?: boolean
+ /** Render date-time columns (timestamp, created_at, last_seen, last_seen_at, session_start,
+ * session_end) as absolute date+time instead of relative ("X ago"). The toggle is exposed
+ * in the column header menu only on EventsQuery / ActorsQuery sources. */
+ showAbsoluteTime?: boolean
/** Can expand row to show raw event data (default: true) */
expandable?: boolean
/** Link properties via the URL (default: false) */
diff --git a/posthog/schema.py b/posthog/schema.py
index 992dfc45c6f8..b7ab8e4a164d 100644
--- a/posthog/schema.py
+++ b/posthog/schema.py
@@ -8064,6 +8064,15 @@ class SavedInsightNode(BaseModel):
kind: Literal["SavedInsightNode"] = "SavedInsightNode"
propertiesViaUrl: bool | None = Field(default=None, description="Link properties via the URL (default: false)")
shortId: str
+ showAbsoluteTime: bool | None = Field(
+ default=None,
+ description=(
+ "Render date-time columns (timestamp, created_at, last_seen, last_seen_at,"
+ ' session_start, session_end) as absolute date+time instead of relative ("X'
+ ' ago"). The toggle is exposed in the column header menu only on'
+ " EventsQuery / ActorsQuery sources."
+ ),
+ )
showActions: bool | None = Field(default=None, description="Show the kebab menu at the end of the row")
showColumnConfigurator: bool | None = Field(
default=None,
@@ -22685,6 +22694,15 @@ class DataTableNode(BaseModel):
| Response26
| None
) = None
+ showAbsoluteTime: bool | None = Field(
+ default=None,
+ description=(
+ "Render date-time columns (timestamp, created_at, last_seen, last_seen_at,"
+ ' session_start, session_end) as absolute date+time instead of relative ("X'
+ ' ago"). The toggle is exposed in the column header menu only on'
+ " EventsQuery / ActorsQuery sources."
+ ),
+ )
showActions: bool | None = Field(default=None, description="Show the kebab menu at the end of the row")
showColumnConfigurator: bool | None = Field(
default=None,
diff --git a/products/product_analytics/frontend/generated/api.schemas.ts b/products/product_analytics/frontend/generated/api.schemas.ts
index eb81b1e51635..e58bae1ab071 100644
--- a/products/product_analytics/frontend/generated/api.schemas.ts
+++ b/products/product_analytics/frontend/generated/api.schemas.ts
@@ -9068,6 +9068,11 @@ export interface DataTableNodeApi {
*/
propertiesViaUrl?: boolean | null
response?: DataTableNodeApiResponse
+ /**
+ * Render date-time columns (timestamp, created_at, last_seen, last_seen_at, session_start, session_end) as absolute date+time instead of relative ("X ago"). The toggle is exposed in the column header menu only on EventsQuery / ActorsQuery sources.
+ * @nullable
+ */
+ showAbsoluteTime?: boolean | null
/**
* Show the kebab menu at the end of the row
* @nullable
diff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.ts
index 339c6864e368..764b95345d11 100644
--- a/services/mcp/src/api/generated.ts
+++ b/services/mcp/src/api/generated.ts
@@ -13715,6 +13715,11 @@ export namespace Schemas {
*/
propertiesViaUrl?: boolean | null;
response?: DataTableNodeResponse;
+ /**
+ * Render date-time columns (timestamp, created_at, last_seen, last_seen_at, session_start, session_end) as absolute date+time instead of relative ("X ago"). The toggle is exposed in the column header menu only on EventsQuery / ActorsQuery sources.
+ * @nullable
+ */
+ showAbsoluteTime?: boolean | null;
/**
* Show the kebab menu at the end of the row
* @nullable
@@ -34050,6 +34055,11 @@ export namespace Schemas {
*/
propertiesViaUrl?: boolean | null;
shortId: string;
+ /**
+ * Render date-time columns (timestamp, created_at, last_seen, last_seen_at, session_start, session_end) as absolute date+time instead of relative ("X ago"). The toggle is exposed in the column header menu only on EventsQuery / ActorsQuery sources.
+ * @nullable
+ */
+ showAbsoluteTime?: boolean | null;
/**
* Show the kebab menu at the end of the row
* @nullable