date format in perl

Hi,
I am searching for data based on date. so what format do I need to use for the below example

Wed Sep  7 02:33:14 EDT 2011

$date= ???
new_perl_userAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
whosbetterthanmeConnect With a Mentor Commented:
my $date = scalar localtime(time());

# this will be close.
0
 
jeromeeCommented:
Nice one!
I've been using Perl for 15 years and it's the first time I run into this wicked trick.
Thank you for sharing whosbetterthanme.
You are starting to deserve your nickname... :-)
0
 
ozoCommented:
since assigning to a scalar implies scalar context, you don't need the explicit scalar function,
and since localtime defaults to using time, you don't need the explicit time function either.

to get exactly the format you requested, you can
use POSIX qw(strftime);  
my $date = strftime "%a %b %e %H:%M:%S %Z %Y", localtime;  
0
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

 
parparovCommented:
You can do without time() since it's default argument of localtime.
However the asker seems to be looking for a date that is not now.

Then my $date = scalar localtime($timestamp_you_have); will do the trick.
0
 
TintinCommented:
Slightly shorter than ozo's version

use POSIX qw(strftime);  
my $date = strftime "%a %b %e %T %Z %Y", localtime;  

Open in new window



jermonee, are you being serious?  In 15 years, you've never used
$date=localtime();

Open in new window

0
 
jeromeeCommented:
Nope.
Always used strftime or sprintf.
Like Larry Wall would say: http://en.wikipedia.org/wiki/There's_more_than_one_way_to_do_it
0
 
whosbetterthanmeCommented:
Well, even though new perl user hasn't responded yet, I suppose it's a matter of old school and using what works!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.