# Date Processing

**URL:** <https://community.graylog.org/t/date-processing/22557>\
**Category:** Graylog Central (peer support)\
**Tags:** pipeline-rules\
**Created:** [February 3, 2022, 3:31pm UTC](https://community.graylog.org/t/date-processing/22557 "2022-02-03T15:31:21Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![danmassa7](https://sea2.discourse-cdn.com/flex016/user_avatar/community.graylog.org/danmassa7/32/9723_2.png) [@danmassa7](https://community.graylog.org/u/danmassa7)\
**Post date:** [February 3, 2022, 3:31pm UTC](https://community.graylog.org/t/date-processing/22557/1 "2022-02-03T15:31:21Z")

</div>

I’m working with rules in the pipelines. I’m trying to get the proper date into Graylog based on the date in the syslog message.  
My Aruba messages are similar to this:  
`<139>Feb 3 10:12:24 2022 mobility01 authmgr[3950]: <132197> <ERRS> <mobility01 192.0.2.5> Maximum number of retries was attempted for station 8c:fc:5a:92:53:d4`

I can grok out the pieces:

```auto
    let extract = grok(
        pattern: "<%{NONNEGINT:syslog_pri}>%{SYSLOGTIMESTAMP:syslog_time} %{YEAR:year}",
        value: to_string($message.message),
        only_named_captures: true
        );

```

But what do I do with this now? I can create a unified field to process:

```auto
    let message_time_str = concat(to_string(extract.syslog_time), " ");
    let message_time_str = concat(to_string(message_time_str), to_string(extract.year));

```

That gives me a field of the form:  
`Feb 3 10:12:24 2022`

Great. But where do I go from here?

If I try to run it through parse\_date()…  
`let date_time_object = parse_date(message_time_str, "MM dd hh:mm:ss yyyy");`  
…it fails with:

```auto
gl2_processing_error
`For rule 'raw-process-exp': In call to function 'parse_date' at 51:27 an exception was thrown: Invalid format: "Feb 3 10:12:24 2022"`

```

I clearly don’t know how to use the parse\_date() function!

Thanks.

### Operating system information

centos-linux-release-8.3-1.2011.el8.noarch

### Package versions

- Graylog 4.0.7
- MongoDB 4.2.14
- Elasticsearch 7.10.2

---

<div class="post-metadata">

**Author:** ![gsmith](https://sea2.discourse-cdn.com/flex016/user_avatar/community.graylog.org/gsmith/32/1222_2.png) [@gsmith](https://community.graylog.org/u/gsmith)\
**Post date:** [February 4, 2022, 12:56am UTC](https://community.graylog.org/t/date-processing/22557/2 "2022-02-04T00:56:25Z")

</div>

Hello,

> [@danmassa7](#):
>
> parse\_date() function!

Perhaps something like this?

```auto
rule “parse date”
when
    has_field(“some_field”)
then
    let new_date = parse_date(to_string($message.some_field), “yyyy-MM-dd’T’HH:mm:ssZZ”));
    set_field(“install_datetime”, new_date);
end

```

Don’t know if you seen this?

[https://docs.graylog.org/docs/functions](https://docs.graylog.org/docs/functions)

Hope that helps

---

<div class="post-metadata">

**Author:** ![danmassa7](https://sea2.discourse-cdn.com/flex016/user_avatar/community.graylog.org/danmassa7/32/9723_2.png) [@danmassa7](https://community.graylog.org/u/danmassa7)\
**Post date:** [February 14, 2022, 3:38pm UTC](https://community.graylog.org/t/date-processing/22557/3 "2022-02-14T15:38:55Z")

</div>

I found a reference that goes into more detail and has examples (the examples are key!)…

> **[Supported date formats - Amazon QuickSight](https://docs.aws.amazon.com/quicksight/latest/user/supported-date-formats.html)**
>
> Amazon QuickSight supports the date and time formats described in this section. Before you add data to Amazon QuickSight, check if your date format is compatible. If you need to use an unsupported format, see .

---

<div class="post-metadata">

**Author:** ![danmassa7](https://sea2.discourse-cdn.com/flex016/user_avatar/community.graylog.org/danmassa7/32/9723_2.png) [@danmassa7](https://community.graylog.org/u/danmassa7)\
**Post date:** [February 14, 2022, 3:44pm UTC](https://community.graylog.org/t/date-processing/22557/4 "2022-02-14T15:44:47Z")

</div>

Here’s where I landed. Thank you @gsmith for your help.

```auto
    let message_time_str = concat(to_string(extract_1.message_timestamp), to_string(extract_1.year));
    let date_time_object = parse_date(
        value: to_string(message_time_str), 
        pattern: "MMM dd HH:mm:ssYYYY",
        timezone: "US/Eastern"
        );
        
    set_field("timestamp", date_time_object);

```

This process gets the year in there and sets the timezone correctly. Finally, it overwrites the **timestamp** field that used to hold the timestamp of when Graylog received the message (the default) but I want it to hold the timestamp that was put into the original syslog message.

I find I’m frequently using the **to\_string()** function and things break down when I don’t use it. Doesn’t it already know it’s a string!? I grew up using Pascal and C++. How the system doesn’t already know it’s a string is beyond me. 😉

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex016/uploads/graylog/original/3X/c/7/c7c09c6b5099570133d6502b83f50ba4430de5b6.png) [@system](https://community.graylog.org/u/system)\
**Post date:** [February 28, 2022, 3:45pm UTC](https://community.graylog.org/t/date-processing/22557/5 "2022-02-28T15:45:06Z")

</div>

Closed on February 28, 2022, 3:45pm UTC

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
