punkwalrus (punkwalrus) wrote,
punkwalrus
punkwalrus

Perl - How do get iso-standard date

For the longest time, I did this the hard way (you don't want to know). Now here's the short way. I needed a way to make a date in the yyyy-mm-dd format. I learned the proper use of the "sprintf" command, and wala!

Differences: printf = when printing a formatted line, sprintf = sending it to variable.

@today=localtime(time);
$year=$today[5] + 1900;
$month=(sprintf "%02d",($today[4] + 1));
$day=(sprintf "%02d",$today[3]);
$foldate=$year."-".$month."-".$day;
Subscribe
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 3 comments