I'm trying to get the last day of the month from 2 months ago. For example, Since the current month is March i'd like to get a date range of 1/31/2011 to 2/28/2011. And If current month was February..then i'd want 12/31/2010 to 01/31/2011. The code i'm using is below...I really appreciate your help!
use POSIX 'strftime';
my @t = (localtime(time));
#mktime(sec, min, hour, mday, mon, year, wday = 0, yday = 0, isdst = 0
my $lastday = POSIX::mktime(0,0,0,0,$t,$t,0,0,-1);
my $lastday_prev = POSIX::mktime(0,0,0,0,$t,$t,0,0,-1);
my @ld_prev = localtime($lastday_prev);
my @ld = localtime($lastday);
print "ld is $ld\n";
print "ld_prev is $ld_prev\n";
my $monthly_date_beg = strftime('%m/' . $ld_prev . '/%Y', $t,$t[
+1], $t, $t, $t-2, $t);
my $monthly_date_end = strftime('%m/' . $ld . '/%Y', $t,$t, $
+t, $t, $t-1, $t);
rint "beg = $monthly_date_beg\n";
print "end = $monthly_date_end\n";
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.
| & || & |
| < || < |
| > || > |
| [ || [ |
| ] || ] ||