Re: Future date
On Sun, Jan 24, 2016 at 11:58:27PM +, Val Krem wrote: > 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? Try It And See. imadev:~$ gdate -d 'December 15, 2016 +1 month' Sun Jan 15 00:00:00 EST 2017 Just to be clear, the -d 'human readable stuff' option is specific to GNU date, and won't work on other systems. Also, the 'human readable stuff' part is NOT specified. There is no documentation for what is allowed there, and what is not. You have to figure it out by trial and error, and it may change between versions of GNU date.
Re: Future date
On Sun, Jan 24, 2016 at 5:30 PM, Val Kremwrote: > 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.
Re: Future date
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 Rutherfordwrote: On Sun, Jan 24, 2016 at 5:30 PM, Val Krem 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.