DateTime Function in Ruby logstash filter

Hi,

I am trying to add a new field which will have value, week of year. Following code is working fine.

ruby {
code => '
require "date"
d = DateTime.new(2017,02,02)
event["Week_of_Year"] = d.cweek
' }

But If I use following code to make it dynamic, it's not working.
ruby {
code => '
require "date"
d = DateTime.new(event["CreateDate"])
event["Week_of_Year"] = d.cweek
' }

I am using Logstash version: 2.3.2

Thanks

Does the CreateDate field contain a string? If yes, use DateTime.strptime to parse the string into a DateTime object.

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