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

Get the date of the day before 1

Status
Not open for further replies.

EfratS

MIS
Aug 4, 2004
15
CA
Hi,

Is there a convinient way to get the privious date before
any given date?

example:
the given date: 01/07/2004
the privious date: 30/06/2004 (the wanted output)

Thanks.
 
Code:
use POSIX;
my $time = '01/07/2004';
my ($d, $m, $y) = split ('/', $time);
my $s = mktime (0, 0, 0, $d - 1, $m - 1, $y - 1900);
($d, $m, $y) = (localtime($s - 86400))[3..5];
$time = sprintf ('%02d/%02d/%04d', $d + 1, $m + 1, $y + 1900);
 
Code:
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time - 86400);
$year += 1900;
$mon += 1;
if($mon <= 9){$mon = "0$mon"};
if($mday <= 9){$mday = "0$mday"};
if($hour <= 9){$hour = "0$hour"};
if($min <= 9){$min = "0$min"};
if($sec <= 9){$sec = "0$sec"};
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top