Your first three solutions are wrong. You assume that every day has 86400 seconds.
use POSIX qw( strftime );
use Time::Local qw( timelocal );
# Pretend we're executing at 12:00:05 am on Mar 12th, 2008.
# The DST time zone change occured on Mar 9th, 2008 here.
my $time = timelocal(5,0,0,12,3-1,2008);
my $offset = 7;
my $date = strftime "%Y-%m-%d",
localtime($time - $offset * 86400);
print("Expecting: 2008-03-05\n");
print("Received: $date\n");
Expecting: 2008-03-05
Received: 2008-03-04
See Re: Get the date (MySQL style) for X days ago for a solution.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|