in reply to Portable previous dates

Should be portable, and probably quicker than most other methods:

#! perl -slw use strict; sub formatYMD { my( $y, $m, $d ) = ( localtime shift )[ 5,4,3 ]; return sprintf "%4d%02d%02d", $y+1900, $m+1, $d; } my $today = my $yesterday = time; $yesterday -= 43200 while substr( localtime( $today ), 0, 3 ) eq substr( localtime( $yesterday ), 0, 3 ); my $lastweek = $yesterday - 13 * 43200; $lastweek -= 43200 while substr( localtime( $yesterday ), 0, 3 ) ne substr( localtime( $lastweek ), 0, 3 ); print ' today: ', formatYMD( $today ); print 'yesterday: ', formatYMD( $yesterday ); print ' lastweek: ', formatYMD( $lastweek ); __END__ c:\test>junk4 today: 20110708 yesterday: 20110707 lastweek: 20110630

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

Replies are listed 'Best First'.
Re^2: Portable previous dates
by Anonymous Monk on Jul 09, 2011 at 13:28 UTC
    Thank you for the feedback BrowserUK, gave me some good insight how to accomplish what I want. Darryl