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!

In reply to Re: Search::Elasticsearch date range by thanos1983
in thread (Solved) Search::Elasticsearch date range by bfdi533

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.