Single digit date to double digit date.

I have a var storing date
var=`date`

Now the date is returned as
Mon Feb 2 00:25:48 PST 2009

Is there any way to check the date field alone ("2" in above case) and if its a single digit then add a prefix 0 to it and store the result in same variable "var"

My intention in above case is to get date as
Mon Feb 02 00:25:48 PST 2009

Plz help.

You can print the date in a given format, something like:

date "+%a %b %d %H:%M %S %Y"

Check the manpage of date.

Regards

hope this helps:

awk '{ 
    day=$3; if (length(day) == 1) day="0"day
    print $1" "$2" "day" "$4" "$5" "$6
}'

Thanks a lot guys, the solution is perfect.

Thanks once again.