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]; print "$someDate\n"; and it printed out: 050303 Wags ;) > $MyDateTime[4]++; > my $someDate = sprintf > "%02d%02d%02d",$MyDateTime[5]%100,$MyDateTime[4],$MyDateTime[4]; > print "$someDate\n"; > > It returned 000101. I need to run this program everyday so that it > takes the system/current date on that day and returns it in the format > yymmdd. > > Thanks. > > > >> >>> get todays date and convert it to yymmdd and assign it to aDate >>> subsitute in a command such as >>> $cmd = "integrate -t push -l $aDate" >>> system($cmd); >>> >>> I will be running this script on unix. But I would like to be able >>> to get the date value platform independant. >>> >>> Thanks. >> >> ******************************************************* >> 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>