LogScale and Time
LogScale has a concept of time with queries that operates on two different bases:
Absolute Time
An absolute time is a specific time, or timestamp, that defines the specific time. For example,
2026-08-27T03:37:59.000Z.To extract single values from a date or time, such as the day, hour or month, there are functions which return the corresponding values. This can be useful in situations where you are aggregating data and want to summarize by month or day of the week. See Extracting Specific Time Values.
For examples of formatting full dates or times in a human-familiar format, see Formatting Dates or Times.
Relative Time
Relative time implies that a given time specification is relative to a specific anchor point or time, for example the start of the query, sub query or the value of another parameter in the same function call.
For example, you might set the time using a relative time specific of
7dwhich means 7 days ago, and then set the end time as1dwhich would mean 1 day ago, meaning a 6 days timespan.LogScale can also report times in the relative format. See Showing a Time Duration.
Times in LogScale are critical to the way data is organized and returned, and all time is expected to be measured from the baseline of the epoch, 1st January 1970, 00:00:00.
Finding and Parsing Timestamps
Timestamps are typically extracted and parsed during ingest. If there are embedded timestamps in other parts of the data, these may need to be explicitly parsed from the source data either during parsing or querying.
In Windows event logs, for example, a timestamp may exist in the embedded XML:
| <Event xmlns=\'http://schemas.microsoft.com/win/2004/08/events/event\'><System><Provider Name=\'Microsoft-Windows-Security-Auditing\' Guid=\'{54849625-5478-4994-A5BA-3E3B0328C30D}\'/><EventID>4634</EventID><Version>0</Version><Level>0</Level><Task>12545</Task><Opcode>0</Opcode><Keywords>0x8020000000000000</Keywords><TimeCreated SystemTime=\'2025-11-30T18:05:45.654321Z\'/><EventRecordID>12349</EventRecordID><Correlation/><Execution ProcessID=\'652\' ThreadID=\'856\'/><Channel>Security</Channel><Computer>DESKTOP-STU345</Computer><Security/></System><EventData><Data Name=\'TargetUserSid\'>S-1-5-21-1234567890-1234567890-1234567890-1002</Data><Data Name=\'TargetUserName\'>user3</Data><Data Name=\'TargetDomainName\'>DESKTOP-STU345</Data><Data Name=\'TargetLogonId\'>0x4567890</Data><Data Name=\'LogonType\'>2</Data></EventData></Event> |
To extract the timestamp from this, the
findTimestamp() function will look at values and
identify whether any of them look like a timestamp and extract it:
parseXml()
| findTimestamp(as=eventts)This puts the value of a timestamp into the eventts field.
If you know the name of the field that contains the timestamp, or you
want to extract a timestamp that is not in a commonly used format, use
the parseTimestamp(). For example, to extract a
timestamp from a field where the data is stored in the format
YYYYMMDD:
| mydate=20251203120000 |
| mydate=20251201120000 |
| mydate=20250104120000 |
| mydate=20250326120000 |
| mydate=20250814120000 |
You must specify the format:
parseTimestamp(field="mydate",format="yyyyMMddHHmmss",as=eventts)
For more examples, see parseTimestamp().
Parsing Non-Standard Times
If the time value is based on a different reference point, for example the epoch is different, or the quantity is different (hours, or days in place of seconds) and then represented only as this differential in the input then the value must separately be calculated and applied to the timestamp value.
For example, a time value measured in seconds calculated from the
1/1/2001 will need to be converted, first by
calculating the difference in seconds between
1/1/1970 and 1/1/2001, then
multiplying the value (in seconds) to get milliseconds:
epoch := 978307200
| newts := (ts*1000) + epoch
| formatTime(format="%m/%d/%Y %H:%M:%S %a", field=ts, as=formatted)Limiting Searches to a Time Range
In general the query environment (whether in the UI or through the API) will set the time range for a given query. However, there may be occasions when you want to limit your search, or a portion of your overall search pipeline, to a range of times based on the ingest or event time.
To set for the whole query, when you cannot directly control the time
range through the search method, use the
setTimeInterval() function:
setTimeInterval(start=7d, end=1d)
IF you want to limit the time interval or search interval of the event
data returned for a subset of the information, The way to achieve this
is to use the test() function to limit your search
to filter on the selected dates:
test(start_hour_utc <= time:hour(@timestamp))
| test(time:hour(@timestamp) <= end_hour_utc)Extracting Specific Time Values
To extract single values, such as the day or hour, there are a number of functions that extract just that single value in an efficient manner. For example, to extract data and summarize it per minute:
minute := time:minute(@timestamp)
| groupBy(minute)Might generate output like this:
| minute | _count |
|---|---|
| 0 | 31 |
| 10 | 29 |
| 2 | 7 |
| 26 | 32 |
| 27 | 58 |
| 28 | 42 |
| 3 | 70 |
| 35 | 12 |
| 36 | 74 |
| 37 | 14 |
| 39 | 18 |
| 4 | 69 |
| 40 | 61 |
| 41 | 64 |
| 5 | 73 |
| 59 | 69 |
| 6 | 32 |
| 7 | 22 |
| 8 | 70 |
| 9 | 70 |
This can also be performed over multiple dimensions, for example, to summarize over day and month:
day := time:dayOfMonth(@timestamp)
| month := time:month(@timestamp)
| groupBy([month,day])Might output this:
| month | day | _count |
|---|---|---|
| 11 | 26 | 445 |
| 12 | 2 | 475 |
| 12 | 3 | 686 |
For more information, see Time and Date Query Functions.
Formatting Dates or Times
To format a date or time in a format that suits your desired output use
the formatTime() function. This supports most of
the formats familiar to users of strftime() or
similar system functions. It uses a format specified to output the
value. For example, to generate the day (as a number) and month (as a
name):
formatTime(@timestamp,format="%d %A")
Would output 12 December (for data on that date).
To summarize by a given date and also use an alternative friendlier date
format, you can use groupBy() to summarize the
value and it's formatted output:
summarydate := formatTime("%m%d")
| display := formatTime("%d %B")
| groupBy([summarydate,job],function=[collect(display),count()])
| drop(summarydate,job)
| groupBy(display,function=sum("_count"))This works by:
Creating both a grouping date and the data to be grouped (job)
Capture the formatted display value using
collect()and count the occurrencesDrop the temporary summarydate and job fields (the count of this will be in the _count field
Summarize the content again by the remaining display field and sum of the values
This might generate output like this:
| display | _sum |
|---|---|
| 01 December | 6906315 |
| 02 December | 6939799 |
| 03 December | 4081142 |
| 26 November | 2906651 |
| 27 November | 6939460 |
| 28 November | 6900940 |
| 29 November | 6897127 |
| 30 November | 6896797 |
Showing a Time Duration
If you have a relative time value, or want to output a value that
represents the difference use the formatDuration()
value. This converts an incoming value (for example seconds or
milliseconds) into a duration. For example, to compare the
@timestamp to the current time, use in combination
with the now() you can subtract the times to get
the value in milliseconds and then convert to a duration:
timediff := (now() - @timestamp)
| formatDuration(timediff,from="ms",as=duration)Which might output something like this:
| duration |
|---|
| 7m36s876ms |
| 7m35s934ms |
| 7m35s162ms |
| 7m34s389ms |
| 7m33s603ms |
| 7m32s825ms |
This may not be a useful measure if you want to summarize something by
the number of days or months 'ago', when it occurred. Instead, you'll
need to calculate the time difference, round the number (so that it's an
integer, not a floating point), and then summarize. For example, to look
for occurrences of the bucket-storage-upload job in
the humio:
humio"bucket-storage-upload"
| nowtime := now()
| timediff := (nowtime - @timestamp)
| basedays := (timediff / (24*60*60*1000))
| daysago := round(basedays)
| groupBy(daysago)Generates a summarized list:
| daysago | _count |
|---|---|
| 0 | 144538 |
| 1 | 287550 |
| 2 | 287533 |
| 3 | 287514 |
| 4 | 287510 |
| 5 | 285692 |
| 6 | 268818 |
| 7 | 137655 |