Subtract 2 months from the date


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Subtract 2 months from the date
# 1  
Old 07-21-2006
Data Subtract 2 months from the date

I have the script which appends month and year to the name of the
file. Now every time when I append the month-year combination I
have to subtract 2 months from the current date and then append
it, since we are sending our vendor 2 months prior worth of data
eveytime.

#! /usr/bin/ksh

filefullname=$1
filename=${filefullname%.*}
fileext=${filefullname##*.}

DATE=`date +%m%y`

newfilename="${filename}${DATE}.${fileext}"

mv $filefullname $newfilename

I am not sure how to go about it, Any help or sample script would help me get going...

Thanks..
# 2  
Old 07-21-2006
Go to the "Answers to frequently asked questions" section. You'll find a whole section on this or similar questions
# 3  
Old 07-21-2006
Java Subtract 2 months from the date

I did happen to look into FAQ section before I posted it here..the solution is with GNU and I am looking for a pure Unix script solution...

Also our OS here does not support

date -v

solution..

Thanks

Last edited by mahekr2000; 07-21-2006 at 07:41 PM.. Reason: added more comment
# 4  
Old 07-21-2006
You'll need to read a few more, there are solutions using pure script, and perl in addition to the gnu method.
# 5  
Old 07-22-2006
ie., see Perderabo's datecalc script
# 6  
Old 07-23-2006
Quote:
Originally Posted by mahekr2000
I did happen to look into FAQ section before I posted it here..
datecalc is mentioned in the third sentence and it is the first solution proposed in the faq article. Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. HP-UX

awk command in hp UNIX subtract 30 days automatically from current date without date illegal option

current date command runs well awk -v t="$(date +%Y-%m-%d)" -F "'" '$1 < t' myname.dat subtract 30 days fails awk -v t="$(date --date="-30days" +%Y-%m-%d)" -F "'" '$1 < t' myname.dat awk command in hp unix subtract 30 days automatically from current date without date illegal option error... (20 Replies)
Discussion started by: kmarcus
20 Replies

2. Shell Programming and Scripting

Subtract a file's modification date with current date

SunOS -s 5.10 Generic_147440-04 sun4u sparc SUNW,SPARC-Enterprise Hi, In a folder, there are files. I have a script which reads the current date and subtract the modification date of each file. How do I achieve this? Regards, Joe (2 Replies)
Discussion started by: roshanbi
2 Replies

3. Shell Programming and Scripting

Subtracting months from passed Date

Hi All, I am getting a date from environment variable and want to do some processing by subtracting 2 months from the date passed through the environment variable. I am trying the following syntax : date_var=2014-08-31 date_2M_ago='$date_var+"%d%m%y" --$date_var="2 months ago" '... (3 Replies)
Discussion started by: Rahul Raj
3 Replies

4. Shell Programming and Scripting

Subtract months/days from date

Hi, Can you please let me know code for the below (in korn shell) a) Subtract month(s) from given date b) Subtract day(s) from give date c) Subtract month(s) from given timestamp d) Subtract day(s) from give timestamp (1 Reply)
Discussion started by: tostay2003
1 Replies

5. UNIX for Dummies Questions & Answers

Subtract minutes from date

Hi, I am reading a particular date from a file using below command WFLWDATE=$(sed '2q;d' FileA.prm) The echo command outputs the correct date in variable WFLWDATE Now I want to subtract 5 minutes from this variable. I am on AIX and unable to get anything working as expected. Can you... (1 Reply)
Discussion started by: vrupatel
1 Replies

6. Shell Programming and Scripting

Subtract date in a loop

I have a file with name and date--- $ cat file.log userA 01-06-2014 userB 25-05-2014 userC 16-05-2014 userC 01-03-2014 I want to search for the current date and get the name for that date. If current date is not found, go back 1 day and search and so on till it finds the... (2 Replies)
Discussion started by: Nagesh_1985
2 Replies

7. HP-UX

Actual date minus six months (HP UX)

Hi there, is it possible to get the actual date minux six months with just a simple command? It's easy with Linux but on HP Unix (for me) impossible ;) Best wishes (3 Replies)
Discussion started by: System
3 Replies

8. Shell Programming and Scripting

How to get date n months before in Unix?

Hi, I need the date n months before currrent date I need to store date in a varible say x and then get the date 6 month before and get the result in the format 25-Aug-2009 Please Advice (7 Replies)
Discussion started by: mad_man12
7 Replies

9. Shell Programming and Scripting

Subtract two date in unix

I Have a long file like this 123122312 05/06/12 123123456 05/06/14 I want to take the difference of dates in two lines & print difference sidewise for the whole long files. Pl help me out. (1 Reply)
Discussion started by: vanand
1 Replies
Login or Register to Ask a Question