I could not find any date functions in the operating system, nor in the C functions that would allow you to obtain the date by subtracting a number from the current date.
However there is a way around this but it is somewhat terse. It requires that you set up some initial parameters to do the calucations. But once completed this utility script can perform the function for many types of applications.
Start with setting up Max Days in each month, include a conditional for leap year.
1. 31
2. 28 2. 29 (leap year)
3. 31
4. 30
5. 31
6. 30
7. 31
8. 31
9. 30
10.31
11.30
12.31
nonlpyr = "312831303130313130313031"
lpyr = "312931303130313130313031"
You can use awk to return the value based on the index position of the selected month.
if today's date (day of Month) - n_days > 0 then
this is easy.
else
this is where it gets a little more involved
remainder = n_days - today's date (day of Month)
if current month = 1 then
prvyear = current year (4 digits) - 1
prvmonth = 12
else
prvmonth = current month - 1
if modulus or remainder of current year / 4 = 0
leap year, use standard Y2K leap year calucation rules
(
has rules for leap year calcs)
use leap year rules to determine leap year
and if prvmonth is 2
if prvmonth = 2
prvmonthdays = 29
else
prvmonthdays = get prvmonth max days of month from list
prvmonthday = prvmonthdays - remainder (from above)
This should give you the year, month, day.
If you use this with $1 argument in a script and place it in the /usr/bin directory it will provide a tool for you to get a date based on the value entered.
Hope this helps.
Scott.