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

Problem with Date::Calc

Status
Not open for further replies.

jpillonel

Programmer
Dec 17, 2003
61
CH
Hello,

I have a problem with Add_Delta_Days function of the Date::Calc module.

The problem id the month returned doesn't have a 0 before the mon the number if it under 10:

Code:
my $dateinputscript = 16032006
my $date = $dateinputscript;
my $day = $date ;
$day =~ s/(\d\d)(\d\d)\d\d(\d\d)/$1/;
my $month = $date;
$month =~ s/(\d\d)(\d\d)\d\d(\d\d)/$2/;
my $year = $date;
$year =~ s/(\d\d)(\d\d)(\d\d\d\d)/$3/;

After I have to add or substract some days with Add_Delta_Days:
Code:
($year1,[COLOR=red] $month1 [/color], $jm1) = Add_Delta_Days($year,$month,$day,
                     -1);

My problem is that the $month1 variable is equal to 3, but I would like to have the two digits format MM for the month --> 03.

I search in the documentation and on internet and found nothing.

Does anyone have an idea ?
 
$month1 = sprintf "%2.2d", $month1;

will make sure it is always 2 digits
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top