Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re^2: Using Time::Piece Strptime

by GrorkGnom (Initiate)
on Jan 26, 2016 at 15:19 UTC ( [id://1153679]=note: print w/replies, xml ) Need Help??


in reply to Re: Using Time::Piece Strptime
in thread Using Time::Piece Strptime

Here's the code piece I am working with:

my $dfile = 'd1528235.txt'; open my $dfh, '<', $dfile; my $date; while ( <$dfh> ) { chomp; if ( not $date and $date = join '/', /=\((\d\d)(\d\d)(\d\d)/ ) { my $str1 = '$date'; my $date1; $date1 = Time::Piece->strptime($date, '%D, %M, %b, %Y') ; $worksheet->merge_range('A2:G2',$date1,$format7,);

This is what I have actually gotten to work and it works pretty well except it gives me the default time in the middle displaying out 00:00:00 between the Day and the Year.

Replies are listed 'Best First'.
Re^3: Using Time::Piece Strptime
by 1nickt (Canon) on Jan 26, 2016 at 16:11 UTC

    Please post a working code snippet and a sample of the input data file if you want help cleaning up your strptime pattern. (see How do I post a question effectively?)

    You can, in any case, eliminate the undesired time part of your output with:

    my $date_sans_time = $date1->strftime("%A %b %e, %Y");
    as I showed above.


    update: added link
    The way forward always starts with a minimal test.

      THANK YOU, THANK YOU, THANK YOU! With all the information you have shown me here and using the CPAN info for strptime and strftime, I've got my date displaying correctly now in my spreadsheet. What a pain!

      Here is the final code that did it. I had to do some manipulating to get it to finally work. Incidently, the raw date I was using from the text file is a Julian calendar date. I generated it from a mainframe job that outputs a set of commands to a text file.

      my $dfile = 'd1528235.txt'; open my $dfh, '<', $dfile; my $date; while ( <$dfh> ) { chomp; if ( not $date and $date = join '/', /=\((\d\d)(\d\d)(\d\d)/ ) { my $str1 = '$date'; my $date1; $date1 = Time::Piece->strptime($date, '%D, %M, %dhd, %Y') ; my $date2 = $date1->strftime("%A %b %d, %Y"); $worksheet->merge_range('A2:G2',$date2,$format5,);
Re^3: Using Time::Piece Strptime
by poj (Abbot) on Jan 26, 2016 at 17:29 UTC

    Date formats in excel can be tricky. See Excel::Writer::XLSX::Utility

    #!perl use strict; use Excel::Writer::XLSX; use Excel::Writer::XLSX::Utility; use Time::Piece; my $wb = Excel::Writer::XLSX->new( 'dates.xlsx' ); my $ws = $wb->add_worksheet(); my $fmt = $wb->add_format(); $fmt->set_num_format( 'dddd mmm dd, yyyy' ); my $date = '3/15/16, 00, Mar, 2016'; my $t = Time::Piece->strptime($date, '%D, %M, %b, %Y') ; my $xldate = xl_date_list($t->year, $t->mon, $t->mday); $ws->write( 0, 0, $xldate, $fmt ); $wb->close();
    poj

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1153679]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (3)
As of 2024-04-19 04:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found