Hi,
I have a CSV file with data in the following format: date,rate1,rate2
e.g.
2009031905,3558,1.68
2009031906,6385,2.42
2009031907,8860,3.68
2009031908,39224,14.16
This data goes all the way back for every hour of the last 40 days however I am attempting to write a perl script to extract the previous business week's (mon-fri) data only.
I have written the following code to decrement the day using the same format however this will not account for previous days overlapping months and years etc.
Can anyone suggest a better way of doing this? I am new to perl and not familiar with how to convert the YYYYMMDDHH string into a date format so I can select a specific range.
@months = qw(01 02 03 04 05 06 07 08 09 10 11 12);
@weekDays = qw(01 02 03 04 05 06 07);
($second, $minute, $hour, $dayOfMonth, $month, $yearOffset, $dayOfWeek
+, $dayOfYear, $daylightSavings) = localtime();
$year = 1900 + $yearOffset;
$theTime = "$year$months[$month]$dayOfMonth$hour";<br>
<br>
$theOldTime = $year. $months[$month]. ($dayOfMonth -2).
$hour;<br>
<br>
print $theTime . "\n";<br>
print $theOldTime . "\n";<br>
Any help would be much appreciated!
Many thanks.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.