CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
How to display the year/quarter information in a filename

 



steve798
Novice

Nov 27, 2017, 2:05 PM

Post #1 of 2 (4498 views)
How to display the year/quarter information in a filename Can't Post

I am writing out a csv file with filename format as region_YYYYMMDDHHMMSS with below declaratives. Example region_20171127112030.csv


Code
my $date    = UnixDate(($opts{'d'} || 'today'), '%q');



Code
my $dumpdir = "$wkdir/region_$date.csv";


How could I make the file format show as region_YYYY-QTRX (where YYYY is the year and X is the quarter number like 1,2,3,4 ) ??

Example: region_2017-QTR3.csv


Laurent_R
Veteran / Moderator

Nov 27, 2017, 4:14 PM

Post #2 of 2 (4496 views)
Re: [steve798] How to display the year/quarter information in a filename [In reply to] Can't Post

Hi,
I don't see any really easy way. Get the two digits for the month (for example with the substr function) and do the conversion, for example with a hash.

For the conversion from month to quarter, you could build on the following example:

Code
perl -e 'printf "%i", (1+($_-1) / 3) for 1..12' 
111222333444


 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives