Computing.Net > Forums > Unix > Date calculations

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Date calculations

Reply to Message Icon

Name: Grace
Date: April 30, 2002 at 12:30:30 Pacific
Comment:

I am looking for a unix script that will calculate a date in the past and also accounts for past months and year. Any help with this would be greatly appreciated. Thanks.



Sponsored Link
Ads by Google

Response Number 1
Name: Rex
Date: April 30, 2002 at 20:20:07 Pacific
Reply:

Need more information.
Give an example on how you want it to work.


0

Response Number 2
Name: Grace
Date: May 1, 2002 at 12:54:00 Pacific
Reply:

I want the script to calculate a date in the past, say 7 days, and then delete certain files based on that date. My problem is that I don't know how to account for going back to the previous month or year. Between May 1st-7th, how do I calculate 7 days before (a date in April) and delete files created on that date?


0

Response Number 3
Name: PaulS
Date: May 2, 2002 at 07:45:04 Pacific
Reply:

I had a similar problem once. There may be a better way to approach it, but think about the following:

1) you know the maximum days in each month.
feb=28, apr,jun,sept,nov=30, all others=31

2) The logic would be something like this.

test for currentday =< 7
get current month = MON
case $MON in
2) maxdays=28;;
4|6|9|11) maxdays=30;;
*) maxdays=31;;
esac

You should be able to do the calculation to get the day in the previous month.



0

Response Number 4
Name: Mark Ward
Date: May 7, 2002 at 17:12:13 Pacific
Reply:

I assume you're trying to delete files that have not been modified for n days?

This would remove files in /myhome/logs that are named *.log and haven't been modified for 7 days or more.

find /myhome/logs -type f ! -mtime -7 -name '*.log' -exec rm {} \;


0

Response Number 5
Name: Grace
Date: May 10, 2002 at 08:40:19 Pacific
Reply:

Thanks for your help! Using both of your suggestions, I waa able to create the script I need.


0

Related Posts

See More



Sponsored Link
Ads by Google
Reply to Message Icon

managing IP address root passwd



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: Date calculations

Date Calculation www.computing.net/answers/unix/date-calculation/8293.html

Get Tomorrow's Date in ddmmyy www.computing.net/answers/unix/get-tomorrows-date-in-ddmmyy-/5648.html

Julian Date for Janurary 1st www.computing.net/answers/unix/julian-date-for-janurary-1st/8488.html