For When You Can't Have The Real Thing
[ start | index | login ]
start > Linux > shell > Last Month

Last Month

Created by dave. Last edited by dave, 11 years and 324 days ago. Viewed 2,737 times. #2
[diff] [history] [edit] [rdf]
labels
attachments

Last Month in shell

(1 June 2012)

This lets you make a string like 2012-05

YEAR=`date +%Y`
MONTH=`date +%m`
MONTH=`expr $MONTH - 1`
if [ "$MONTH" -eq 0 ] ; then
    YEAR=`expr $YEAR - 1`
    MONTH=12
fi
if [ "$MONTH" -lt 10 ] ; then
    MONTH="0$MONTH"
fi
OUTPUT="$YEAR-$MONTH"

I really shouldn't have to keep inventing this wheel, but I do.

no comments | post comment
This is a collection of techical information, much of it learned the hard way. Consider it a lab book or a /info directory. I doubt much of it will be of use to anyone else.

Useful:


snipsnap.org | Copyright 2000-2002 Matthias L. Jugel and Stephan J. Schmidt