Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have Linux ( RH 5.3) machine

I need to add/calculate 10 days plus date so then I will get new date (expiration date))

for example

 # date 
 Sun Sep 11 07:59:16 IST 2012

So I need to get

     NEW_expration_DATE = Sun Sep 21 07:59:16 IST 2012

Please advice how to calculate the new expiration date ( with bash , ksh , or manipulate date command ?)

share|improve this question
add comment

migrated from serverfault.com Sep 25 '12 at 0:17

This question came from our site for professional system and network administrators.

2 Answers

up vote 5 down vote accepted

You can just use the -d switch and provide a date to be calculated

date
Sun Sep 23 08:19:56 BST 2012
NEW_expration_DATE=$(date -d "+10 days")
echo $NEW_expration_DATE
Wed Oct 3 08:12:33 BST 2012 
  -d, --date=STRING
          display time described by STRING, not ‘now’

This is quite a powerful tool as you can do things like

date -d "Sun Sep 11 07:59:16 IST 2012+10 days"
Fri Sep 21 03:29:16 BST 2012

or

TZ=IST date -d "Sun Sep 11 07:59:16 IST 2012+10 days"
Fri Sep 21 07:59:16 IST 2012

or

prog_end_date=`date '+%C%y%m%d' -d "$end_date+10 days"`
So if $end_date=20131001, $prog_end_date=20131011
share|improve this answer
add comment

You can use "+x days" as format string:

$ date -d "+10 days"
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.