Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PARAMETER (First day of month and yesterdays date) HELP

Status
Not open for further replies.

mheilbut

Programmer
Apr 24, 2002
53
BR
The following is used to get the first day of the month and yesterdays date to put in as parameters:

@t = localtime();
$tmon = $t[4] + 1;
$tmon = &quot;0&quot; . $tmon if ($tmon < 10);
$tyear = $t[5] + 1900;
$firstday = join(&quot;-&quot;, &quot;01&quot;, $tmon, $tyear);

$time = time();
@y = localtime($time - 86400); # 1 day is 86400 seconds
$ymon = $y[4] + 1;
$ymon = &quot;0&quot; . $ymon if ($ymon < 10);
$ymday = $y[3];
$ymday = &quot;0&quot; . $ymday if ($ymday < 10);
$yyear = $y[5] + 1900;
$ydate = join(&quot;-&quot;, $ymday, $ymon, $yyear);

my $repres = $ARGV[0];
my $ini = &quot;'&quot;.$firstday.&quot;'&quot;;
my $fim = &quot;'&quot;.$ydate.&quot;'&quot;;

How do I change this so I can say that if todays date is the first day of the month, then the program should get the first day of last month and yesterdays date?
Something like this:
if today = 1 then (FirstDay) of Month-1 and Yesterday else
FirstDay and Yesterday. Michel, São Paulo, Brazil
 
Add the following line after where you're getting the current day's information, but after where you assign your month and year.

Code:
#today's date
$tday = $t[3];
#if today is the first day of the month
if ($tday eq &quot;01&quot;)
{
#and if the month is January
    if ($tmon eq &quot;01&quot;)
    {
 #make the month December
       $tmon = 12;
    }
    else
    {
#subtract 1 from the variable that contains the month
        $tmon--;
    }
}

- Rieekan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top