Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

create array from strftime

by mhearse (Chaplain)
on Jun 20, 2012 at 17:37 UTC ( #977425=perlquestion: print w/replies, xml ) Need Help??
mhearse has asked for the wisdom of the Perl Monks concerning the following question:

Is there a way to do:
my ($day, $month, $year) = strftime "%d %m %Y", time();
Because that doesn't populate the array.

Replies are listed 'Best First'.
Re: create array from strftime
by ikegami (Pope) on Jun 20, 2012 at 17:45 UTC

    Problem #1: strftime doesn't take an epoch time for argument.

    Problem #2: strftime returns a single string.

    Then there's also the fact that "3 scalars" are not "an array".


    my ($day, $month, $year) = (localtime)[3,4,5]; $month += 1; $year += 1900;


      Or read the output of strftime(3). :)
      Here's another example:
      use POSIX qw(strftime); # POSIX is your friend # see man strftime(3) for format options my $gmtstring = strftime "%F %H:%I:%S %z", localtime; print $gmtstring;

      Hope this helps.

      my $perl_version( 5.12.4 );
      print $perl_version;
        How does one use that to populate $day, $month and $year?
Re: create array from strftime
by Anonymous Monk on Jun 20, 2012 at 17:44 UTC

    <serious joker>Sure, all you do is stuff some dynamite into your pants and light the fuze

    the opposite of strftime is strptime, DateTime comes with both

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://977425]
Approved by ikegami
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (4)
As of 2018-03-17 04:36 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (223 votes). Check out past polls.