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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date change modules

Status
Not open for further replies.

newtarge

ISP
Oct 27, 2003
21
0
0
US
Hi, does perl have a module to help me with a small problem on date changing.

I have a script which zips up archived log files and names them with the date minus 1 since the logs are from the previous day. The issue here is when I get to the 1st day of the next month the file would be called something like this "0dec2003-server.tar.gz" instead of 30nov2003-server.tar.gz" if that module is out there what is the syntax to use it?
 
Date::Calc does this very well. You can tell it things like 'Give me the date of today - 1' and it figures it all out really well.
 
Take a look at thread219-728867

Blue [dragon]

If I wasn't Blue, I would just be a Dragon...
 
Code:
#!/usr/bin/perl
$now=&get_time;
print "$now";


sub get_time {

 (@date)=reverse(localtime(time-86400));
  $date[3] += 1900; # years start from 1900
  $date[4]++; # months are zero-based
  my $now = "$date[3]-".sprintf("%0.2d",$date[4])."-".sprintf("%0.2d",$date[5])." ".sprintf("%0.2d",$date[6]).":".sprintf("%0.2d",$date[7]).":".sprintf("%0.2d",$date[8]);
  return $now;
}

Here's something to play with
HTH
Paul
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top