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) 1

Status
Not open for further replies.

mheilbut

Programmer
Apr 24, 2002
53
BR
I need to put in my date parameter the date of the first day of the month and in another yesterday's date (today minus one).
How do I do this in PERL? Michel, São Paulo, Brazil
 
Go on CPAN and find a Perl module that does it for you. Seriously.

--jim
 
Is this what you need?
Code:
# Get current month
@t = localtime();
$tmon = $t[4] + 1;
$tmon = &quot;0&quot; . $tmon if ($tmon < 10);
$tyear = $t[5] + 1900;
$firstday = join(&quot;-&quot;, $tmon, &quot;01&quot;, $tyear);
print &quot;first day of month was $firstday \n&quot;;
# Get yesterday's date
$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;, $ymon, $ymday, $yyear);
print &quot;yesterday's date was $ydate \n&quot;;
 
Raider2001, I get the following problem when using your program:

syntax error near unexpected token 'localtime()'
'@t = localtime();'

What do I do? Michel, São Paulo, Brazil
 
NEVERMIND!!
I forgot to put that inicial command line that all programs must have.
THANX a bunch!!
Michel, São Paulo, Brazil
 
I have yet another question though:
How do I put this in my program?
It starts like this:

#!/usr/bin/perl

use DBI;

my $data = $ARGV[0];
my $datb = $ARGV[1];

and brings from another file this:

#!/usr/bin/perl

#include <stdio.h>
use DBI;
use POSIX qw(strftime);
use CGI qw/:standard/;

my $repres = $ARGV[0];
my $ini = &quot;'&quot;.$ARGV[1].&quot;'&quot;;
my $fim = &quot;'&quot;.$ARGV[2].&quot;'&quot;;

#print header,
print start_html('Pedidos'),
h1('Pedidos de '.$ini.' ate '.$fim);

Any thoughts? Thanx. Michel, São Paulo, Brazil
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top