Get date one month from today


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Get date one month from today
# 1  
Old 08-15-2008
Get date one month from today

I need to get the date one month in the future from today - or 30 days from today etc...

I need this to work all year around - I cannot find anything to solve this issue in the search / faqs etc....
# 2  
Old 08-15-2008
Its okay - just found I can use something like the below


curmth=`date +%m`
set -A mth 01 02 03 04 05 06 07 08 09 10 11 12
nextmth=${mth[$((curmth))]}
echo $nextmth

curday=`date +%d`
curyear=`date +%Y`

todaynextmonth=$curyear$nextmth$curday
echo "todaynextmonth is $todaynextmonth"

Last edited by frustrated1; 08-15-2008 at 06:16 AM..
# 3  
Old 08-15-2008
Your script doesn't work in December.

Did you actually look in the FAQ section? https://www.unix.com/answers-frequent...rithmetic.html
# 4  
Old 08-15-2008
try this this will give you exact 30 days future date from todays date

fnsonlq0-/home/fnsonlq0>date
Fri Aug 15 15:44:59 IST 2008
fnsonlq0-/home/fnsonlq0>TZ=IST-720
fnsonlq0-/home/fnsonlq0>date
Sun Sep 14 10:15:06 IST 2008
fnsonlq0-/home/fnsonlq0>TZ=IST-5:30
fnsonlq0-/home/fnsonlq0>date
Fri Aug 15 15:45:11 IST 2008
# 5  
Old 08-15-2008
Quote:
Originally Posted by frustrated1
I need to get the date one month in the future from today - or 30 days from today etc...

I need this to work all year around - I cannot find anything to solve this issue in the search / faqs etc....
Using the --date option lets You chose how You want it

date --date='1 month'
date --date='10 days ago'

/Lakris
# 6  
Old 08-15-2008
hi Lakris i don't think all unix has that --date option
because AIX don't have any such option...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Compare Date to today's date in shell script

Hi Community! Following on from this code in another thread: #!/bin/bash file_string=`/bin/cat date.txt | /usr/bin/awk '{print $5,$4,$7,$6,$8}'` file_date=`/bin/date -d "$file_string"` file_epoch=`/bin/date -d "$file_string" +%s` now_epoch=`/bin/date +%s` if then #let... (2 Replies)
Discussion started by: Greenage
2 Replies

2. UNIX for Beginners Questions & Answers

How bash treats literal date value and retrieve year, month and date?

Hi, I am trying to add few (say 3 days) to sysdate using - date -d '+ 3 days' +%y%m%d and it works as expected. But how to add few (say 3 days) to a literal date value and how bash treats a literal value as a date. Can we say just like in ORACLE TO_DATE that my given literal date value... (2 Replies)
Discussion started by: pointers1234
2 Replies

3. Shell Programming and Scripting

Not able to fetch previous month first date and last date

I am not able to fetch first date and last date previous month date -d -1month +%Y-%m-%d date -d -1month +%Y-%m-%d I need two format dd-mm-yyy previous month 01-03-2016 previous month 31-03-2016 and also only date 1 to 31 Aprriciate your replay (4 Replies)
Discussion started by: jagu
4 Replies

4. Shell Programming and Scripting

Need to add a date column (today's date) in file

Hi I have file with number status and date1 and date1 field, want add a column today between column date1 and date2. file1.txt number status date1 date2 ===== ==== === ===== 34567 open 27/06/13 28/06/13 45678 open 27/06/13 28/06/13 43567 open 27/06/13 28/06/13 ... (1 Reply)
Discussion started by: vijay_rajni
1 Replies

5. Shell Programming and Scripting

UNIX date fuction - how to deduct days from today's date

Hi, One of my Unix scripts needs to look for files coming in on Fridays. This script runs on Mondays. $date +"%y%m%d" will give me today's date. How can I get previous Friday's date.. can I do "today's date minus 3 days" to get Friday's date? If not, then any other way?? Name of the files is... (4 Replies)
Discussion started by: juzz4fun
4 Replies

6. Shell Programming and Scripting

Help with getting last date of previous month and first date of previous 4th month from current date

I have requirment to get last date of previous month and the first date of previous 4th month: Example: Current date: 20130320 (yyyymmdd) Last date of previous month: 20130228 (yyyymmdd) First date of previous 4th month: 20121101 (yyyymmdd) In my shell --date, -d, -v switches are not... (3 Replies)
Discussion started by: machomaddy
3 Replies

7. Shell Programming and Scripting

[Solved] Replace yesterday date with today's date except from the first line

Hello, I have a file like this: 2012112920121130 12345620121130msABowwiqiq 34477420121129amABamauee e7748420121130ehABeheheei in case the content of the file has the date of yesterday within the lines containing pattern AB this should be replaced by the current date. But if I use... (3 Replies)
Discussion started by: Lilu_CK
3 Replies

8. UNIX for Dummies Questions & Answers

Shell Scripts - shows today’s date and time in a better format than ‘date’ (Uses positional paramete

Hello, I am trying to show today's date and time in a better format than ‘date' (Using positional parameters). I found a command mktime and am wondering if this is the best command to use or will this also show me the time elapse since 1/30/70? Any help would be greatly appreciated, Thanks... (3 Replies)
Discussion started by: citizencro
3 Replies

9. UNIX for Dummies Questions & Answers

print previous month (current month minus 1) with Solaris date and ksh

Hi folks month=`date +%m`gives current month Howto print previous month (current month minus 1) with Solaris date and ksh (7 Replies)
Discussion started by: slashdotweenie
7 Replies

10. UNIX for Dummies Questions & Answers

compare today's date with date in a file

Hi I am very new to scripting, Can someone show me how to (in unix shell script) compare the system's date with a date in a file. The requirement is to somehow open this file (which will only have a date in it) and compare it with today's date. If they are equal execute a procedure below but if... (4 Replies)
Discussion started by: siog
4 Replies
Login or Register to Ask a Question