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

Changing the output year format 1

Status
Not open for further replies.
Feb 16, 2003
87
GB
Hello! This little piece of code here comes from the OpenSRS system and very nicely outputs the next six years as four digit numbers (2003, 2004, 2005, 2006, 2007, 2008)

BUT can anyone make it so it only outputs two digit numbers (eg 03, 04, 05, 06, 07, 08)????

Hope someone can help!

sub get_cc_years {

my (%years,$i);
my $year = (localtime)[5];
$year += 1900;

for ($i = 0; $i <=5; $i++) {
$years{$year} = $year;
$year++;
}

return \%years;

}

Thanks!
 
Here's one way to do it, but there are better ones--change this:

$years{$year} = $year;

to this:

$years{$year} = substr($year,2,4);

All the best,

John A
see me fulminate at
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top