On Sun, 11 Feb 2007 03:51:17 -0500 Mathew Snyder <[EMAIL PROTECTED]> wrote:
> Jeff Pang wrote: > >> #!/usr/bin/perl > >> > >> use warnings; > >> use strict; > >> > >> my @date = (localtime (time - (24*60*60)))[3..5]; > >> > >> foreach my $i (@date) { > >> print $i . "\n"; > >> } > >> > >> exit; > >> > >> I get this: > >> > >> 10 > >> 1 > >> 107 > >> > >> > >> I still have to add 1 to the month. Is that right? Also, the year still > >> needs > >> to be fixed by adding 1900 but from what I've read that is due to the way > >> computers work and not necessarily because of Perl. > >> > > > > I think it's better to write: > > > > my ($day,$month,$year) = (localtime (time - (24*60*60)))[3..5]; > > > > and you still need to add these two statements: > > > > $month++; > > $year+=1900; > > I need to make sure $day and $month are in 2-digit format so that wouldn't > work. > At least, not anyway I'm presently familiar with. I tried to use sprintf in > there but it failed because of not enough arguments. Then try this my ($day,$month,$year) = (localtime (time - (24*60*60)))[3..5]; $month++; $year+=1900; my $dmy = ( sprintf( "%02d %02d %04d", $day , $month , $year ) ); print "$dmy\n"; Owen -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/