> -----Message d'origine-----
> De : Wagner, David --- Senior Programmer Analyst --- WGO
> [mailto:[EMAIL PROTECTED]
> Envoyé : jeudi 3 mars 2005 21:40
> À : Nishi Prafull
> Cc : beginners@perl.org
> Objet : RE: Perl program to convert system date to yymmdd
> 
> Nishi Prafull wrote:
> > On Thu, 3 Mar 2005 12:12:35 -0800, Wagner, David --- Senior
Programmer
> > Analyst --- WGO <[EMAIL PROTECTED]> wrote:
> >> Nishi Prafull wrote:
> >>> HI:
> >>>
> >>> I want to write a perl script that would compute the date in the
> >>> format yymmdd(050303) and subsitute it for a variable in the perl
> >>> script. This variable is thereafter subsituted in a command that
> >>> will be run inside the script.
> >>>
> >>> myTest.pl
> >>>
> >>> var aDate;
> >>        You can do it a number of ways, here is a start on one way:
> >>
> >> my @MyDateTime = ();
> >> @MyTime = localtime( time );
> >> $MyDateTime[4]++;               #months start at zero, so must add
1
> >> # # Now the array has the date and time info in the following
> >> elements: #    0    1    2     3     4    5     6     7     8
> >> #   (sec, min, hour, mday, mon, year, wday, yday, isdst) # mday is
> >> Day of Month # year is number of eyars from 1900
> >> # wday is day of week: 0:Sun and 6: Sat
> >> # yday is number of days from 1 Jan
> >> # isdst if true then Daylight savings time is on
> >>        So to get your date in the format:
> >> my $aDate = sprintf "%02d%02d%02d",
> >>                                        $MyDateTime[5] % 100,
> >>                                        % does a modulo against the
> >>                                        year, so 105 comes out as 5,
> >> 106 as 6 $MyDateTime[4], $MyDateTime[4];
> >>
> >> $aDate should now have 050303
> >>
> >> Wags ;)
> > Hi:
> > Thanks.
> > I tried the above but it did not return the correct result
> > my @MyDateTime = ();
> > @MyTime = localtime(time);
>       Missed this and it should be @MyDateTime and not @MyTime
> 
> Also as part of your code, you should always use:
> 
> use strict;
> use warnings;
> 
>       By doing this it will cut down on the number of problems you run
> into.
> I made the program as :
> 
> #!perl
> 
> use strict;
> use warnings;
> 
> my @MyDateTime = ();
> @MyDateTime = localtime(time);
> $MyDateTime[4]++;
> my $someDate = sprintf "%02d%02d%02d",
>                                 $MyDateTime[5]%100,
>                                 $MyDateTime[4],$MyDateTime[4];

Typo ?
You twice $MyDateTime[4]
Souldn't be: $MyDateTime[4],$MyDateTime[3]; ?

You just lucky that today the month and day have same value 03 :-)

Regards,
José.



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to