Since your dates are in YYYYMMDDHH format you can use string comparisons to decide whether the datum is in the correct range. This script decrements the current epoch time value by the relevant number of seconds needed to go back to the Friday of the previous week and then another four days to get to the Monday. It then constructs start and end timestamp strings for hour 0 of the Monday and hour 23 of the Friday.

use strict; use warnings; my %daysOffsetTV = ( 0 => 86400 * 2, 1 => 86400 * 3, 2 => 86400 * 4, 3 => 86400 * 5, 4 => 86400 * 6, 5 => 86400 * 7, 6 => 86400, ); my $nowTV = time(); my $dayOfWk = ( localtime( $nowTV ) )[ 6 ]; my $prevWkFriTV = $nowTV - $daysOffsetTV{ $dayOfWk }; my( $friDay, $friMth, $friYr ) = ( localtime( $prevWkFriTV ) )[ 3 .. 5 ]; $friMth += 1; $friYr += 1900; my $endDate = sprintf q{%04d%02d%02d%02d}, $friYr, $friMth, $friDay, 23; my $prevWkMonTV = $prevWkFriTV - 86400 * 4; my( $monDay, $monMth, $monYr ) = ( localtime( $prevWkMonTV ) )[ 3 .. 5 ]; $monMth += 1; $monYr += 1900; my $startDate = sprintf q{%04d%02d%02d%02d}, $monYr, $monMth, $monDay, 0; print qq{Starting date: $startDate\n}, qq{ Ending date: $endDate\n\n}; while( <DATA> ) { my $timestamp = ( split m{,} )[ 0 ]; print unless $timestamp lt $startDate or $timestamp gt $endDate; } __END__ 2009030822,3558,1.68 2009030823,6385,5.47 2009030900,7485,1.82 2009030901,8563,4.35 2009031322,8860,3.68 2009031323,39224,14.16 2009031400,34553,7.34 2009031401,7353,5.74

The output.

Starting date: 2009030900 Ending date: 2009031323 2009030900,7485,1.82 2009030901,8563,4.35 2009031322,8860,3.68 2009031323,39224,14.16

I hope this is of interest.

Cheers,

JohnGG


In reply to Re: Extract data between certain dates using YYYYMMDDHH timestamp by johngg
in thread Extract data between certain dates using YYYYMMDDHH timestamp by chud83

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.