in reply to Re: Local Date Format
in thread Local Date Format

Hope this helps, just pass the subroutine a 1 to have it return month/day/year ex: 02/22/2005 or pass it nothing to return $Year$RealMonth${Day}_$Hour${Minute} ex:20050222_122. You can of course play around with the output to return diff formats
sub getdate{ my $ret = "$_[0]"; # Get the all the values for current time my ($Second, $Minute, $Hour, $Day, $Month, $Year, $WeekDay, $DayOf +Year, $IsDST) = localtime(time); # In Perl, you'll need to increment the month by 1 my $RealMonth = $Month + 1; # Months of the year are not zero-base +d # Perl code will need to be adjusted for one-digit months if($RealMonth < 10) { $RealMonth = "0" . $RealMonth; # add a leading zero to one-digi +t months } # How to add a leading zero in Perl if($Day < 10) { $Day = "0" . $Day; # add a leading zero to one-digit days } # How to use modulo arithmetic in Perl if($Year >= 100) { $Fixed_Year = ($Year % 100); } else { $Fixed_Year = $Year; } # 1900 is subtracted from the value returned from localtime # Add it back in to get a 4-digit year $Year += 1900; # Format the string the way we want if ($ret == "1"){ $today = "$RealMonth\/$Day\/$Year"; return $today; } else{ $today = "$Year$RealMonth${Day}_$Hour${Minute}"; return $today; } }

Replies are listed 'Best First'.
Re^3: Local Date Format
by gaal (Parson) on Feb 22, 2005 at 17:08 UTC
    This doesn't look like what the original poster was after, at all.
Re^3: Local Date Format
by meredith (Friar) on Feb 22, 2005 at 23:13 UTC

    You should check out POSIX::strftime, too. :)

    use POSIX qw(strftime); print "mm/dd/yyyy:\t". strftime('%d/%m/%Y', localtime time) . $/; print "yyyymmdd_hhmm:\t". strftime('%Y%m%d_%H%M', localtime time) . $/ +;

    These also have the benefit of zero-padding the date and time components, so they will sort correctly if used in a filename (for example).

    mhoward - at - hattmoward.org