bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Future date


From: Dave Rutherford
Subject: Re: Future date
Date: Sun, 24 Jan 2016 18:31:06 -0500

On Sun, Jan 24, 2016 at 5:30 PM, Val Krem <valkrem@yahoo.com> wrote:
> I am trying to get a variable that combines the next month(Feb) and current  year (2016) from the current date
[...]
> temp_date=$(date | awk -F ' ' '{print $2,$6}' | tr  -d ' ')

Wow, that's overkill. You don't need the -F ' ' options to awk, since
that's the default. You don't need tr to remove the space because
awk will happily not print one if you omit the comma.

And you don't need awk in the first place because date will handle
the desired output directly if you just ask it to.

> I got  Jan2016.
> but I want  this "Feb2016" next month and current year. How do I do that?
>
> Well at the end of the year, I will have another problem ( ie., to change it to next year)

date -d 'next month' +%b%Y

Note, I'm not sure that's robust if you call it on, say, the 31st of the month
if the next month doesn't have 31 days. It might give you two months from now.
Read the man page for date for further enlightenment.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]