http://qs321.pair.com?node_id=32018


in reply to Date format question

printf and more generally sprintf allow you to specify how wide you want fields to print. printf just takes the string returned by sprintf and actually prints it, but the format specifiers are documented with sprintf. Try this:

printf("%4d.%02d.%02d\n", $year, $month, $day);

Update:

As BlaisePascal points out, this snippet assumes that the variables already contain what you want to print out; you may need to coerce return values from time functions to get them into the appropriate form.