?
Solved

Date in Perl

Posted on 2011-10-18
7
Medium Priority
?
343 Views
Last Modified: 2012-05-12
Hi,
How to get the day before yesterday date in Perl.

0
Comment
Question by:new_perl_user
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 2

Expert Comment

by:wiredpea
ID: 36986513
localtime() - 3600 * 2
0
 

Author Comment

by:new_perl_user
ID: 36986744
Hi,

I did like this;

$date = localtime() - 3600 * 2;

print "$date\n";

Result: -7200
0
 

Author Comment

by:new_perl_user
ID: 36986770
Got it as:

my $yesterday = localtime(time()-48*60*60)
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Expert Comment

by:wiredpea
ID: 36987803
that is what I meant ;)
0
 
LVL 85

Expert Comment

by:ozo
ID: 36988117
Note that if daylight saving time applies in your locale, there may be 4 hours during the year, near midnight, when that would produce an incorrect answer.
0
 
LVL 3

Expert Comment

by:tumtum73
ID: 36991824
http://www.nntp.perl.org/group/perl.perlfaq.workers/2011/02/msg701.html

This script resolves the DST issues...

use Time::Local;
my $today = timelocal 0, 0, 12, ( localtime )[3..5];
my ($d, $m, $y) = ( localtime $today-(86400*2) )[3..5];
printf "Day before yesterday: %d-%02d-%02d\n", $y+1900, $m+1, $d;
0
 
LVL 85

Accepted Solution

by:
ozo earned 2000 total points
ID: 36993248
localtime time-(36+(localtime)[2])*60*60  
suffices to resolve the DST issue without need of modules
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans
Suggested Courses

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question