Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Get yesterday's date on the terminal, mac os x



Not off topic ;-) I need to get last month from the date

So, do this

MON=`date +"10#%m"`
((MON=$MON-1))
echo $MON
8


I hate when I do that. Of course if you do this in January your MON becomes zero and other things need to adjust like the year.


Suppose you want to write out a web statistics report for last month, with an appropriate filename.
I do believe this handles the boundary condition, and invokes "date" the fewest times possible. ;-)


#!/bin/sh

MYDATE=`date +"%Y%m"`
YEAR=${MYDATE:0:4}
MONTH=$((10#${MYDATE:4:2} - 1))
[[ $MONTH == 0 ]] && MONTH=12 && ((YEAR--))

theReport=Web-Report-Monthly-$YEAR-$MONTH.html
#

it's just too early for me ;-)

8)
----------------------------------
Chris Janton  - face at CentosPrime dot COM
Netminder for Opus1.COM


_______________________________________________ Do not post admin requests to the list. They will be ignored. Macos-x-server mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/macos-x-server/email@hidden

This email sent to email@hidden


Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.