Newsgroups: comp.unix.shell
From: Tapani Tarvainen <t...@it.jyu.fi>
Date: 12 Feb 2002 17:33:11 +0200
Local: Tues, Feb 12 2002 10:33 am
Subject: Re: yesterday's date under the shell
"Jean-Noêl" <J...@freckles.de> writes: No, it does not work on all systems at all times. > To determine the yesterday date i do it so: > TZ=PST+24 date +%d > it work well but my question is: > does this work on all systems and all shells > or should i do it otherwise ??? In some it will work practically always, on others never, on most it works sometimes and sometimes not. I would recommend against it. Unfortunately there is no short and sweet portable #! /usr/bin/sh # Date calculations using POSIX shell # Julian Day Number from calendar date } # Calendar date from Julian Day Number julian2date() # julianday { tmpday=$(($1 - 1721119)) centuries=$(( (4 * tmpday - 1) / 146097)) tmpday=$((tmpday + centuries - centuries/4)) year=$(( (4 * tmpday - 1) / 1461)) tmpday=$((tmpday - (1461 * year) / 4)) month=$(( (10 * tmpday - 5) / 306)) day=$((tmpday - (306 * month + 5) / 10)) month=$((month + 2)) year=$((year + month/12)) month=$((month % 12 + 1)) print $day $month $year } # Day of week, Monday=1...Sunday=7 dow() # day month year { print $(( $(date2julian $1 $2 $3) % 7 + 1)) } ################################# The End ################################# Those allow rather arbitrary date computations. julian2date $(( $(date2julian $(date +"%d %m %Y") ) - 1 )) -- You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
| ||||||||||||||