I am trying to run a report and output it to a file with yesterdays date, the only problem I am having at the moment is getting the filename to be yesterdays dates.
I have 2 methods I am currently trying and it's not working very well.
first is:
#!/usr/local/bin/perl -w
use strict;
use DBI;
use DBD::Oracle;
use Text::CSV;
$ENV{ORACLE_HOME}="/oracle";
my $user = "fyiuser";
my $password = "fyiuser";
my $dbh;
$dbh = DBI->connect("dbi:Oracle:fyidocs.com", $user, $password, { RaiseError => 0, AutoCommit => 0 }) or die ("Could not conn
ect to DB");
my $yest_date = $dbh->prepare("select to_char(sysdate-1,'YYYYMMDD') from dual");
my $filename = $yest_date . ".csv";
print "$filename\n";
And this outputs: DBI::st=HASH(0x2758ec).csv
but is supposed to output: 20080203.csv
I don't know what I am doing wrong with this one. The next thing I am trying, I don't know how to format the date correctly is:
#!/usr/bin/perl
$yesterday = time() - ( 24 * 60 * 60 );
my $lastday = (localtime $yesterday);
print "$lastday \n";
This outputs: Sun Feb 3 20:28:57 2008
but I can't really use that as the filename, I would like just the year/month/day possibly "2008Feb3" would be nice.
Does anyone have any ideas on how to create a file and give it yesterdays date as a name?
I have 2 methods I am currently trying and it's not working very well.
first is:
#!/usr/local/bin/perl -w
use strict;
use DBI;
use DBD::Oracle;
use Text::CSV;
$ENV{ORACLE_HOME}="/oracle";
my $user = "fyiuser";
my $password = "fyiuser";
my $dbh;
$dbh = DBI->connect("dbi:Oracle:fyidocs.com", $user, $password, { RaiseError => 0, AutoCommit => 0 }) or die ("Could not conn
ect to DB");
my $yest_date = $dbh->prepare("select to_char(sysdate-1,'YYYYMMDD') from dual");
my $filename = $yest_date . ".csv";
print "$filename\n";
And this outputs: DBI::st=HASH(0x2758ec).csv
but is supposed to output: 20080203.csv
I don't know what I am doing wrong with this one. The next thing I am trying, I don't know how to format the date correctly is:
#!/usr/bin/perl
$yesterday = time() - ( 24 * 60 * 60 );
my $lastday = (localtime $yesterday);
print "$lastday \n";
This outputs: Sun Feb 3 20:28:57 2008
but I can't really use that as the filename, I would like just the year/month/day possibly "2008Feb3" would be nice.
Does anyone have any ideas on how to create a file and give it yesterdays date as a name?