in reply to (Solved) Search::Elasticsearch date range

Hello bfdi533,

Unfortunately I do not have anything to contribute to your question, but as I was reading your question I noticed how you collect the `date`.

On the sample of code that you provide us you do not use all the following parameters anywhere $dt and $latest_dt. I assume you are using them somewhere else on your code.

The way that you collect the date it might work on LinuxOS but I guess it will not work on WindowsOS (I assume as I can test it). So in order to make your code able to be executable on all OS I propose the following solution.

test.pl

#!/usr/bin/perl use strict; use warnings; use Date::Manip; # I assume you do not want to use the underscore alternatively just ad +d it my $date = UnixDate(ParseDate("now"), "%Y-%m-%d %T"); print $date . "\n"; my $dt = `date +%F_%T`; chomp $dt; print $dt . "\n"; my $latest_dt; my $dateAlternativeFormat = UnixDate(ParseDate("now"), "%a %b %d %T %Z + %Y"); print "Starting run at: ".`date`; print "Starting run at: ".$dateAlternativeFormat."\n"; __END__ $ perl test.pl 2018-04-25 11:28:18 2018-04-25_11:28:18 Starting run at: Wed Apr 25 11:28:18 CEST 2018 Starting run at: Wed Apr 25 11:28:18 CEST 2018

I am using the module Date::Manip. It is not the easiest module that you can use but the date manipulations that you can do with this module are infinite. Some examples for future study Date::Manip::Examples. Regarding the format of the date when you want to alter it, you can read more about it here: Date::Manip::Date::PRINTF_DIRECTIVES.

Hope this helps for future usage. BR / Thanos

Seeking for Perl wisdom...on the process of learning...not there...yet!

Replies are listed 'Best First'.
Re^2: Search::Elasticsearch date range
by bfdi533 (Friar) on Apr 25, 2018 at 14:21 UTC

    Thank you very much for your reply.

    I actually use $dt and $latest_dt later in my code and did not realize I left them in the test for this post.

    I actually use Date::Manip as well in my code so your post/reply is very welcome. I realize that `date` is probably not the best option and does create some overhead to spawn that out. I do not need to run this on any other OS so that is not part of the consideration while developing this tool. `date` is a bad habit I picked up long ago and just need to stop copying this from code to code to code when I need the current date.

    I will use your example going forward as it is a much better alternative, as you have pointed out.