Add 1 year to System date in script

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Add 1 year to System date in script
# 1  
Old 09-02-2009
Add 1 year to System date in script

Hi All,

I wanted to add 1 year to the system date in my script.

say export start_date=`date +%F`
echo $start_date
o/p of this is 2009-09-02

To this i want to add 1 year.
the output i need here is 2010-09-02

can anybody help me ?

Thanks in advance,
# 2  
Old 09-02-2009
One "stupid" way to do that :
export start_date=$(echo $(echo `date +%Y` + 1 | bc)-$(date +%m)-$(date +%d))

There must be a smarter solution ^^
# 3  
Old 09-02-2009
man date like always Smilie
On FreeBSD I use
# date -v +1y +%F

# 4  
Old 09-02-2009
well...since years don't have awkward diferent lengths like months you could do:

date +%F | awk  '{FS=OFS="-";$1++;print}'

# 5  
Old 09-02-2009
My awk don't like Tytalus solution
date +%F | awk  'BEGIN{FS=OFS="-"}{$1++}1'

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Answers to Frequently Asked Questions

Compare date in .txt with system date and remove if it's lesser than system date

I m working on shell scripting and I m stuck where in my .txt file there is column as expiry date and I need to compare that date with system date and need to remove all the rows where expiry date is less than system date and create a new .txt with update. (1 Reply)
Discussion started by: Stuti
1 Replies

2. UNIX for Beginners Questions & Answers

Compare date in .txt with system date and remove if it's lesser than system date

Can someone help me with the code wherein there is a file f1.txt with different column and 34 column have expiry date and I need to get that and compare with system date and if expiry date is <system date remove those rows and other rows should be moved to new file f2.txt . I don't want to delete... (2 Replies)
Discussion started by: Stuti
2 Replies

3. UNIX for Beginners Questions & Answers

How bash treats literal date value and retrieve year, month and date?

Hi, I am trying to add few (say 3 days) to sysdate using - date -d '+ 3 days' +%y%m%d and it works as expected. But how to add few (say 3 days) to a literal date value and how bash treats a literal value as a date. Can we say just like in ORACLE TO_DATE that my given literal date value... (2 Replies)
Discussion started by: pointers1234
2 Replies

4. Shell Programming and Scripting

Find week of the year for given date using date command inside awk

Hi all, Need an urgent help on the below scenario. script: awk -F"," 'BEGIN { #some variable assignment} { #some calculation and put values in array} END { year=#getting it from array and assume this will be 2014 month=#getting it from array and this will be 05 date=#... (7 Replies)
Discussion started by: vijaidhas
7 Replies

5. Shell Programming and Scripting

How to list files that are not first two files date & last file date for every month-year?

Hi All, I need to find all files other than first two files dates & last file date for month and month/year wise list. lets say there are following files in directory Mar 19 2012 c.txt Mar 19 2012 cc.txt Mar 21 2012 d.txt Mar 22 2012 f.txt Mar 24 2012 h.txt Mar 25 2012 w.txt Feb 12... (2 Replies)
Discussion started by: Makarand Dodmis
2 Replies

6. UNIX for Dummies Questions & Answers

[Solved] Previous Year Date

Hi Gurus, I would like to get the date for the previous year based on the date I specify. For e.g. If I input today's date (i.e. 20130422) I need to get 20120422. We don't have GNU and use K Shell. Any help is highly appreciated. Thanks Shash (4 Replies)
Discussion started by: shash
4 Replies

7. Shell Programming and Scripting

get date for all saturdays in given year

Hello Guys I browsed through site for mentioned requirement all solutions I got in perl I am looking for something in unix script for same any suggestions thanks (1 Reply)
Discussion started by: joshiamit
1 Replies

8. Shell Programming and Scripting

Derive the Year value from the date value

Hi All, I have two dates: PREVIOUS_DAY and CURRENT_DAY. I need to test the these two values years are same or not. PREVIOUS_DAY like '%y%m%d' i.e values like 111010, 111011, 111012 etc. For CURRENT_YEAR:'date +%Y' use this command. How can derive the year value from PREVIOUS_DAY and... (1 Reply)
Discussion started by: pdathu
1 Replies

9. Shell Programming and Scripting

Run script from another script if system date was reached

I what to find a system date in a shell script and search for it in a file in specific record. If the record (ENDC) has the same date I what to execute another shell script. Here is example of the file: Can someone please help me with this ? (3 Replies)
Discussion started by: Lenora2009
3 Replies

10. UNIX for Dummies Questions & Answers

Date Script problem for year cross over

Hello, I'm very new to script writing - everything I have I got off the Internet. I'm pretty sure I stole this date script from this site. Anyway, the script works great until I try to obtain a date that falls into last year. I can get 'Dec 31, 2009' but nothing earlier. Below is the... (3 Replies)
Discussion started by: Colel2
3 Replies
Login or Register to Ask a Question