Date Filter Returns Empty Results When Data Exists #164

Closed
opened 2026-04-05 16:18:59 +02:00 by MrUnknownDE · 0 comments
Owner

Originally created by @TomTom-Labs on 1/14/2026

Summary

When using the date filter on Monitor Logs, the filter returns empty results even when log entries are clearly visible within the selected time range (without the filter applied).


Steps to Reproduce

  1. Navigate to Monitor → View → Logs page
  2. Observe that log entries are displayed (without any filter)
  3. Note the timestamp of a visible log entry
  4. Set the "Monitor at" filter to include that timestamp:
  5. Observe that the results are empty

Expected Behavior

The filter should return all log entries within the selected date range. The log entry visible in step 3 should appear in the filtered results.


Actual Behavior

The filter returns empty results, even though log entries exist within the selected time range.

Image Image

Notes

Assumed Root Cause

The issue may be caused by a timezone mismatch between the query and the database.

File 1: Common/Server/Utils/AnalyticsDatabase/Statement.ts (line 121)

Date values are serialized using toDatabaseDate():

} else if (v.value instanceof Date) {
  finalValue = OneUptimeDate.toDatabaseDate(v.value);
}

File 2: Common/Types/Date.ts (lines 1500-1508)

Two date formatting methods exist with different timezone handling:

// Line 1500-1503: Formats in LOCAL timezone
public static toDatabaseDate(date: Date): string {
  date = this.fromString(date);
  return moment(date).format("YYYY-MM-DD HH:mm:ss");
}

// Line 1505-1508: Formats in UTC timezone
public static toClickhouseDateTime(date: Date | string): string {
  const parsedDate: Date = this.fromString(date);
  return moment(parsedDate).utc().format("YYYY-MM-DD HH:mm:ss");
}

If ClickHouse stores timestamps in UTC but queries are formatted in local timezone, this mismatch could cause the filter to miss valid data.


Update Statement.ts to use the UTC formatting method instead of toDatabaseDate():

Line 121:

} else if (v.value instanceof Date) {
  finalValue = OneUptimeDate.toClickhouseDateTime(v.value);
}

Line 130:

if (typeof v !== "string" && v.type === TableColumnType.Date) {
  finalValue = OneUptimeDate.fromString(finalValue as string);
  finalValue = OneUptimeDate.toClickhouseDateTime(finalValue);
}

This would ensure all date queries use UTC formatting, matching the timestamps stored in ClickHouse.

*Originally created by @TomTom-Labs on 1/14/2026* ### Summary When using the date filter on Monitor Logs, the filter returns empty results even when log entries are clearly visible within the selected time range (without the filter applied). --- ### Steps to Reproduce 1. Navigate to **Monitor → View → Logs** page 2. Observe that log entries are displayed (without any filter) 3. Note the timestamp of a visible log entry 4. Set the "Monitor at" filter to include that timestamp: 5. Observe that the results are empty --- ### Expected Behavior The filter should return all log entries within the selected date range. The log entry visible in step 3 should appear in the filtered results. --- ### Actual Behavior The filter returns empty results, even though log entries exist within the selected time range. <img width="1471" height="518" alt="Image" src="https://github.com/user-attachments/assets/df822c60-15d4-4069-b6ce-409dd8e679d9" /> <img width="1456" height="849" alt="Image" src="https://github.com/user-attachments/assets/32e6b818-fb91-46e7-a083-07a5526b7316" /> --- ### Notes #### Assumed Root Cause The issue may be caused by a timezone mismatch between the query and the database. **File 1: `Common/Server/Utils/AnalyticsDatabase/Statement.ts` (line 121)** Date values are serialized using `toDatabaseDate()`: ```typescript } else if (v.value instanceof Date) { finalValue = OneUptimeDate.toDatabaseDate(v.value); } ``` **File 2: `Common/Types/Date.ts` (lines 1500-1508)** Two date formatting methods exist with different timezone handling: ```typescript // Line 1500-1503: Formats in LOCAL timezone public static toDatabaseDate(date: Date): string { date = this.fromString(date); return moment(date).format("YYYY-MM-DD HH:mm:ss"); } // Line 1505-1508: Formats in UTC timezone public static toClickhouseDateTime(date: Date | string): string { const parsedDate: Date = this.fromString(date); return moment(parsedDate).utc().format("YYYY-MM-DD HH:mm:ss"); } ``` If ClickHouse stores timestamps in UTC but queries are formatted in local timezone, this mismatch could cause the filter to miss valid data. --- ### Recommended Solution (if assumption is correct) Update `Statement.ts` to use the UTC formatting method instead of `toDatabaseDate()`: **Line 121:** ```typescript } else if (v.value instanceof Date) { finalValue = OneUptimeDate.toClickhouseDateTime(v.value); } ``` **Line 130:** ```typescript if (typeof v !== "string" && v.type === TableColumnType.Date) { finalValue = OneUptimeDate.fromString(finalValue as string); finalValue = OneUptimeDate.toClickhouseDateTime(finalValue); } ``` This would ensure all date queries use UTC formatting, matching the timestamps stored in ClickHouse.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github/oneuptime#164