> For the complete documentation index, see [llms.txt](https://cortex-docs.paloaltonetworks.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://cortex-docs.paloaltonetworks.com/xql-command-reference-guide/readme/functions/current_time.md).

# current\_time

Use the `current_time()` function to return a `TIMESTAMP` value representing the exact time at which the query is executed.

## Syntax

```sql
current_time()
```

## Parameters

The `current_time()` function does not accept any parameters.

## Returns

The `current_time()` function returns a `TIMESTAMP` representing the current system time.

## Usage notes

* The functıon is particularly useful for calculations that require the current moment as a reference point, such as determining the age of an event or establishing dynamic time windows.
* The function returns the timestamp according to the default Timestamp Format specified in Server Settings.
* The function is typically used within the `alter` or `filter` stages.

## Examples

### Example 1: Assigning current\_time() to a new field in an alter stage

**Goal**: Create a new field that holds the current timestamp for each record.

**XQL code**:

```sql
config timeframe = 1d 
| dataset = sample_xql_raw 
| alter current_query_timestamp = current_time() 
| fields event_id, current_query_timestamp 
| limit 3
```

**Explanation**: The `current_time()` function provides the exact time of query execution, which is then assigned to the `current_query_timestamp` field for every record.

**Output**:

| EVENT\_ID | CURRENT\_QUERY\_TIMESTAMP |
| --------- | ------------------------- |
| 101       | Jul 25th 2024 14:30:00    |
| 102       | Jul 25th 2024 14:30:00    |
| 103       | Jul 25th 2024 14:30:00    |

### Example 2: Using current\_time() within timestamp\_diff() in a filter stage

**Goal**: Filter events that occurred more than 1 day ago relative to the current time.

**XQL code**:

```sql
config timeframe = 1d 
| dataset = sample_xql_raw 
| filter timestamp_diff(current_time(), _time, "DAY") > 1 
| fields event_id, _time 
| limit 3
```

**Explanation**: The `timestamp_diff()` function calculates the difference between the current time and the event's `_time`. The `filter` stage retains only those records where the difference is greater than 1 day.

**Output**:

| EVENT\_ID | \_TIME                 |
| --------- | ---------------------- |
| 101       | Oct 26th 2023 10:00:00 |
| 102       | Oct 26th 2023 10:05:30 |
| 103       | Oct 26th 2023 10:15:15 |

### Example 3: Using current\_time() within date\_floor() in an alter Stage

**Goal**: Round the current time down to the nearest week.

**XQL code**:

```sql
config timeframe = 1d 
| dataset = sample_xql_raw 
| alter current_week_start = date_floor(current_time(), "w") 
| fields event_id, current_week_start 
| limit 3
```

**Explanation**: The `date_floor()` function, when applied to `current_time()`, truncates the timestamp to the beginning of the specified unit ("w" for week).

**Output**:

| EVENT\_ID | CURRENT\_WEEK\_START   |
| --------- | ---------------------- |
| 101       | Jul 21st 2024 00:00:00 |
| 102       | Jul 21st 2024 00:00:00 |
| 103       | Jul 21st 2024 00:00:00 |

### Example 4: Using current\_time() within extract\_time() in an alter Stage

**Goal**: Extract a specific part of the current time, such as the hour.

**XQL code**:

```sql
config timeframe = 1d 
| dataset = sample_xql_raw 
| alter current_hour = extract_time(current_time(), "HOUR") 
| fields event_id, current_hour 
| limit 3
```

**Explanation**: The `extract_time()` function isolates the "HOUR" component from the current timestamp provided by `current_time()`, returning an integer representing that hour.

**Output**:

| EVENT\_ID | CURRENT\_HOUR |
| --------- | ------------- |
| 101       | 14            |
| 102       | 14            |
| 103       | 14            |

### Example 5: Filtering events based on process execution age

**Goal**: From the `xdr_data` dataset, retrieve events from the last 24 hours where the actor process began running more than 30 days prior to the current time.

**XQL Code**:

```sql
dataset = sample_xql_raw
| filter timestamp_diff(current_time(), to_timestamp(actor_process_execution_time, "MILLIS"), "DAY") > 30
```

**Explanation**: This query uses current\_time() to get the present timestamp and to\_timestamp() to convert the actor\_process\_execution\_time (stored in milliseconds) into a standard timestamp format. The timestamp\_diff() function then calculates the number of days between these two points. The filter stage ensures only records with a difference greater than 30 days are returned.

**Output**

| event\_id | actor\_process\_execution\_time | \_time                  | calculated\_days\_old |
| --------- | ------------------------------- | ----------------------- | --------------------- |
| 5521      | 1693569600000                   | 2023-10-15 08:30:00 UTC | 44                    |
| 5589      | 1691064000000                   | 2023-10-15 09:12:00 UTC | 73                    |
| 5602      | 1688212800000                   | 2023-10-15 10:05:00 UTC | 106                   |

## Related articles

* **Stages**: [`alter`](/xql-command-reference-guide/readme/stages/alter.md), [`filter`](/xql-command-reference-guide/readme/stages/filter.md)
* **Functions**: [`timestamp_diff`](/xql-command-reference-guide/readme/functions/timestamp_diff.md), [`date_floor`](/xql-command-reference-guide/readme/functions/date_floor.md), [`extract_time`](/xql-command-reference-guide/readme/functions/extract_time.md)
* **Datasets**: [`xdr_data`](https://www.google.com/search?q=%5Bhttps://docs-cortex.paloaltonetworks.com/r/Cortex-XQL-Schema-Reference-Guide/Introduction%5D\(https://docs-cortex.paloaltonetworks.com/r/Cortex-XQL-Schema-Reference-Guide/Introduction\))


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://cortex-docs.paloaltonetworks.com/xql-command-reference-guide/readme/functions/current_time.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
