I need to calc eg "today-x_days" or "today+x_days)".
I may not use perl, phyton etc., I have only ksh or bash available.
OS: Sparc Solaris 8, 9 and 10.
I assume that this is not trivial, becase of eg. leap years.
Example, for calculation of "yesterday":
yesterday=today - 1_day
If today is 1st of March, yesterday may be 28th or 29th of Feb.
This should be treated correctly at leap years.
I really would appreciate any help!
Regards, Roland
> I need to calc eg "today-x_days" or "today+x_days)".
[misc]$ date
Thu Mar 29 19:17:37 BST 2007
[misc]$ date --date="28 days ago"
Thu Mar 1 19:17:47 GMT 2007
[misc]$ date --date="30 days ago"
Tue Feb 27 19:18:00 GMT 2007
Note that this isn't quite correct, since it doesn't take into
account the hour lost over daylight savings time...
That requires GNU date. On some systems it may be installed as
gdate.
If you don't have it, and cannot install it, there are a number of
shell functions which manipulate dates in Chapter 8 of my book.
That chapter is on-line at:
<http://cfaj.freeshell.org/shell/ssr/08-The-Dating-Game.shtml>.
--
Chris F.A. Johnson <http://cfaj.freeshell.org>
========= Do not reply to the From: address; use Reply-To: ========
Author:
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)