Re: Script to output yesterday's day of the month (201 Views)
Reply
Regular Advisor
dev44
Posts: 164
Registered: ‎03-20-2002
Message 1 of 6 (201 Views)

Script to output yesterday's day of the month

Hi,

I need to output yesterday's day of the month. But, I need it to print out as "01" not "1". Presently I do: d=`expr $(date +%d) - 01` but all this does is prints out a 1. I need a 01.

Thanks,
whatever
Exalted Contributor
Steven E. Protter
Posts: 33,806
Registered: ‎08-15-2002
Message 2 of 6 (201 Views)

Re: Script to output yesterday's day of the month

Shalom,

Check out the man page on printf.

Here is an example of formatted output.

ipcs | awk '{total=total+$5};END {printf "%6.3f\n",total/1024/1024/1024 }'

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Regular Advisor
dev44
Posts: 164
Registered: ‎03-20-2002
Message 3 of 6 (201 Views)

Re: Script to output yesterday's day of the month

Found a way around the problem...with if/then statement
whatever
Acclaimed Contributor
Dennis Handly
Posts: 25,094
Registered: ‎03-06-2006
Message 4 of 6 (201 Views)

Re: Script to output yesterday's day of the month

Instead of using printf(1), you can use the shell directly:
typeset -Z2 d=$(( $(date +%d) - 1 ))

Of course this doesn't work too well on the first or the first of the year.
Valued Contributor
Fredrik.eriksson
Posts: 237
Registered: ‎09-01-2008
Message 5 of 6 (201 Views)

Re: Script to output yesterday's day of the month

A little google revealed this:
# echo `(export TZ=XYZ+24; date "+%Y-%m-%d")`

Look here for more :)
http://forums11.itrc.hp.com/service/forums/questionanswer.do?threadId=9251

Best regards
Fredrik Eriksson
Acclaimed Contributor
Dennis Handly
Posts: 25,094
Registered: ‎03-06-2006
Message 6 of 6 (201 Views)

Re: Script to output yesterday's day of the month

>Fredrik: A little google revealed this:

If you look a litter further, you'll find this is not supported, safe nor work all the time.

And you can simplify it to just:
TZ=XYZ+24 date "+%Y-%m-%d"
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation.