tech-userlevel archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: Weekday abbreviations in output of cal(1)
On Tue, Jun 30, 2020 at 11:24:51AM +0200, Michael Siegel wrote:
> Well, how would you use date(1) to return the number of days in any
> given month, for example?
Good example, slightly complex but still close to cal|wc ;-)
Martin
--8<--
#! /bin/sh
YEAR=2020
MONTH=6
if [ $MONTH -lt 12 ]; then
next_year=$YEAR
next_month=$(( $MONTH + 1 ))
else
next_year=$(( $YEAR + 1 ))
next_month=1
fi
ms=$( date -d "${YEAR}-${MONTH}-1" '+%s' )
ns=$( date -d "${next_year}-${next_month}-1" '+%s' )
diff=$(( $ns - $ms ))
days=$(( $diff / 86400 ))
echo "${YEAR}-${MONTH} has ${days} days"
Home |
Main Index |
Thread Index |
Old Index