Date filter for logstash seems to change date to older value - elastic-stack

I am parsing logs in the format
2017-04-03 05:48:16,129....
I am parsing this using grok as
match => {"message" => "%{TIMESTAMP_ISO8601:timestamp},.*\|%{DATA:logLevel}\|.*\|.*\|.*\|.*\|.*\|%{DATA:service}\|.*\|.*\|.*\|%{DATA:successMsg} :%{USERNAME:loginUser}"}
After this I am applying date filter to get timestamp value as -
date {
match => [ "timestamp", "yyyy-mm-dd HH:mm:ss" ]
target => "timestamp"
}
The value I receive in elastic is offset by 3 months.
ie - 2017-04-03 05:48:16 is coverted to January 3rd 2017, 05:48:16
All other fields are fine. Where am I going wrong?

Found an answer somewhere else.
https://discuss.elastic.co/t/date-filter-for-logstash-seems-to-change-date-to-older-value/80983
It's only that the month should be MM and not mm. Not sure how this led to the behavior though.

Related

Logstash: How to match the timezone ID 'CET' in a date filter pattern?

In Logstash, I want to convert a string into a timestamp using the date filter. The string looks follows:
Fri Nov 05 06:24:28.651 CET 2021
I've tried the following pattern to no avail:
date {
match => [ "syslog_timestamp", "EEE MMM dd HH:mm:ss.SSS ZZZ yyyy"]
locale => "en_US"
timezone => "Europe/Berlin"
target => "syslog_timestamp"
}
This is confusing since Logstash is said to use the Joda library and Joda in turn says 'CET' is a legal timezone ID. I confirmed the results by testing the Jody library v2.10.13 directly in a Java application.
How to parse CET/CEST in the date filter?
Since time zone names (z) cannot be parsed and ZZZ still wouldn't match the daylight-saving variant 'CEST' according to Joda's documentation, I worked around this issue in Logstash by handling the timezone code as text and passing multiple patterns with the standard time zone and daylight-saving time zone to the filter:
match => [ "syslog_timestamp", "EEE MMM dd HH:mm:ss.SSS 'CET' yyyy", "EEE MMM dd HH:mm:ss.SSS 'CEST' yyyy"]

Logstash _dateparsefailure matching timestamp with date plugin

I have a json input with the String field timestamp that I want to parse to date in the field #timestamp in elasticsearch.
The input timestamp field: 2021-06-20 03:37:14.595000+00:00
This is how I've set up the filter in logstash:
date {
match => ["timestamp", "ISO8601", "yyyy-MM-dd HH:mm:ss.SSSSSS+ZZ:ZZ", "yyyy-MM-dd HH:mm:ss.SSSSSS"]
target => "#timestamp"
}
The input string is in ISO8601 format, so using only "ISO8601" should work. However, I'm getting the _dateparsefailure. Therefore, I've also tried with the patterns "yyyy-MM-dd HH:mm:ss.SSSSSS+ZZ:ZZ" and "yyyy-MM-dd HH:mm:ss.SSSSSS", with no luck.
I've also tried to set the target to something else, like my_timestamp, in case the value of #timestamp is being overwritten, but that didn't work either.
Could you help me understand why this does not work?
ZZ is used to match "colon in between hour and minute offsets" so you should use "yyyy-MM-dd HH:mm:ss.SSSSSS+ZZ".

Wrong day when using day()-formula with format - PowerBI

I'm trying to find out the weekday i.e Mon, Tue, Wed etc. from a date-range formatted as yyyy mm dd
I tried to use the formula format(day(Date Table),"ddd"), but the weekday is wrong. In my example, the output of 2020.01.01 gives Sunday, but it should be Wednesday.
I think your formula is wrong:
Instead of
format(day(Date Table),"ddd")
Use
format(<Target Table>[<date column>],"ddd")
I.e. Omit the DAX DAY call. This is resulting in the day of the month (1..31) being passed to the format function.
When you use the DAY function in DAX, it returns the day of the month (1 through 31).
Thus DAY ( DATE ( 2020, 1, 1) ) = 1 which means you're trying to format the number 1 as a date. Integers are interpreted as days since 1899/12/30 when treated as a date, so 1 corresponds to 1899/12/31, which happened to be a Sunday. Thus FORMAT(1, "ddd") = "Sun".
There's no reason to get DAY involved here. You can simply write
Day = FORMAT ( 'Calendar'[Date], "ddd" )

Comparing Dates in If Statement

I am trying to compare dates in an expression. If the Closed_Date matches today's date (I am using Today()), then it would output 1 in the box, otherwise output 0. So far I have this but it doesn't seem to work:
=IIF(Fields!Closed_Date = Mid(Today(),1,9), "1", "0")
The reason I am using Mid is to just get the month, day, and year. I don't want the time included. Is there a way you can compare dates using this or another method?
Today() actually returns today's date at midnight, so to compare your date to today you'll need to strip the time from Closed_Date instead. I'd recommend the DateValue function, since it returns date information with time set to midnight which makes for an easy comparison:
=IIF(DateValue(Fields!Closed_Date.Value) = Today(), "1", "0")
Try something like this:
=IIF(
Format(CDate(Fields!Closed_Date), "MM/dd/yyyy") = Today()
, "1", "0"
)
OR
=IIF(
FormatDateTime(Fields!Closed_Date, DateFormat.ShortDate) = Today()
, "1", "0"
)
Avoid using string functions like Mid with the dates. There are lot of date related functions available in SSRS.

Parsing String to date doesnt work

I tried parsing a string in a namedQuery, but it seems doesnt work. I have this code in my domain class:
searchBirthdaten{ q ->
def dates = Date.parse("yyyyy:MM:dd HH:mm:ss", "2011-9-21 00:00:00")
eq 'birthDate' , dates)
}
But I always got this error:
Unparseable date: "2011-9-21 00:00:00"
I really dont understand why this is happening. Any idea?
Your date input string has to be in the format you defined: yyyy:MM:dd HH:mm:ss (corrected)
So your 3 issues were:
You are using the "-" character to delimit you date for parsing but your format string is using ":"
You have 5 ys in your format string i.e. yyyyy:MM.... Which won't be valid for another 8 thousandish years ;)
You define your month format as MM but you are passing only '9', this will need to be '09' to match your fomat string.