At this year's YAPC::EU, we've been having a blast in Granada, Spain, an incredibly beautiful city. The conference has been fun and Dave Cross gave a great lightning talk about Modern PERL (sic). These are devs who are using 5.8, often aren't allowed to use modules, and use CGI.pm for param handling, but print cookies manually. In a similar spirit, I present a subroutine from some client code. It's here with their permission, and it's one of reasons they've hired All Around The World to fix their system. Pay close attention to the sprintf lines.

Enjoy!

sub getDate { my $DATE = "0"; # Get the date ($day, $month, $year, $hour, $min, $sec) = (localtime)[3, 4, 5, 2, 1, 0]; # Reformat numbers to have two digits $day = sprintf ( "%.2d", $day % 100 ); $month++; $month = sprintf ( "%.2d", ($month++) % 100 ); $hour = sprintf ( "%.2d", $hour % 100 ); $min = sprintf ( "%.2d", $min % 100 ); $sec = sprintf ( "%.2d", $sec % 100 ); # Fix the year $year = $year + 1900; # Format the date. $DATE = "$day$month$year$hour$min$sec"; # Return the date return $DATE; }

I should add that this is some of the nicer code in their system.