Problems? Is your data what you think it is? PerlMonks

### create array from strftime

by mhearse (Hermit)
 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.

Comment on create array from strftime
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

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".

Solution:

```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?

Create A New User
Node Status?
node history
Node Type: perlquestion [id://977425]
Approved by ikegami
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (26)
As of 2013-12-11 17:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?