Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Normally the solution would be simply:
my $yesterday = time() - (24 * 60 * 60); my ($day, $month, $year) = localtime($yesterday)[3,4,5];
(Remember to add one to the value of $month and 1900 to the value of $year before printing them out.)

However, yesterday's date may not be twenty-four hours ago. The day on which daylight savings time (DST) ends is 25 hours long; the day on which DST begins is only 23 hours long.

Thus if you calculated the date 24 hours earlier during the last hour of the day DST ended you would get an erroneous result using the above formula, i.e., "yesterday's" and today's dates would be the same.

Similarly if you calculated the date 24 hours earlier during the first hour of the first whole day after DST began you would also get an erroneous result using the above formula: "yesterday's" date would be two days before today's date.

'perldoc perlfaq4' has a workaround by Russ Allbery that fixes the DST problem.

Update: Corrected above to state that the formula at top would provide incorrect results in the last hour of the day DST ended, not the first hour of the day after it ended.


In reply to Re: date by sierrathedog04
in thread Yesterday's or last month's date? by renpai

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • 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.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (4)
As of 2024-03-29 01:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found