Hi All: Thanks for the replies.It works correctly. I need to do similar thing for extracting the time in the format hhmm ie if it 2:05 pm then i need to display 1405
If the date command returns Thu Mar 3 13:56:24 PST 2005 then i need to convert the time format to 1356 Please let me know how I can do this. Thanks. On Thu, 3 Mar 2005 13:01:24 -0800, Wagner, David --- Senior Programmer Analyst --- WGO <[EMAIL PROTECTED]> wrote: > Jose Nyimi wrote: > >> -----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]; ? > yes it should be. Any other day and it would hav stood out as wrong, > but missed it. > Wags ;) > > > > You just lucky that today the month and day have same value 03 :-) > > > > Regards, > > José. > > ******************************************************* > This message contains information that is confidential > and proprietary to FedEx Freight or its affiliates. > It is intended only for the recipient named and for > the express purpose(s) described therein. > Any other use is prohibited. > ******************************************************* > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > <http://learn.perl.org/> <http://learn.perl.org/first-response> > > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>