bug-bash
[Top][All Lists]
Advanced

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

Re: Future date


From: Val Krem
Subject: Re: Future date
Date: Sun, 24 Jan 2016 23:58:27 +0000 (UTC)

Thank you very much! 


So easy, I am just learning about bash scripting.
date -d 'next month' +%b%Y
What would happen in December 2016. Will it give me Jan2017?

Val!


On Sunday, January 24, 2016 5:31 PM, Dave Rutherford <dave@evilpettingzoo.com> 
wrote:



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]