How to display a date, 30 days from the current date?

Well guys,

I know the right syntax for displaying the current date is $(date). However, I am planning to send emails to some customers which displays their subscription date, and then the expiry. The expiry being 30 days from the current date.

What would the right syntax be?

Try this:

date --date="30 days"
Thu Feb 23 13:43:50 EST 2012

Thank you :slight_smile:

$ x="2012-01-25"
$ date -d "$x +30days" +%Y-%m-%d
2012-02-24

@balajesuri
The UNIX and PERL guru...

Thanks all.

I scripted it in this way:

 
echo "enter expiry in days (Ex: 30 60 90 120)"
 read expiry
  future=$(date --date="$expiry days" +"%d/%m/%Y")

Then for the email:

Account Expiry Date: $future

Some of the systems (eg Solaris) may not have those features in the 'date' command. If you are looking for portable solution, you may want to use perl. I believe most of the modern system will have perl 4 or above.

Here is my function that you can adopt in your shell script

function later()
{
  perl -e '
    $t=time()+'${1:-30}'*86400;
    @t=localtime($t);
    printf("%04d-%02d-%02d",$t[5]+1900,$t[4]+1,$t[3]);'
}
later 30