|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Hi, I am trying to display future date from the current date but unable to do so in UNIX (not in PERL). For eg: if today is March 5 then I want a variable wherein I can store Mar 7 date, but unable to get the future date from the current date. I have tried many possible ways as mentioned below but all in vain. Kindly help me out as soon as possible Code:
echo `date "+%b%e" -d "+3 days"` echo `date "+%b%e" -d "+3 days in future"` echo `date --date="-1 days" +%Y%m%d` Last edited by methyl; 03-05-2012 at 12:16 PM.. Reason: please use code tags |
| Sponsored Links | ||
|
|
#2
|
|||
|
|||
|
Try this mate, Code:
echo THISISAVARIABLE=$(date -d "+3days" + %Y-%m-%d) Last edited by methyl; 03-05-2012 at 12:19 PM.. Reason: code tags ; remove spaces from equals |
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
Hi Banned, When I do so, see the error below: ------------------ Code:
$ echo `date -d "+3days" + %Y-%m-%d`
date: illegal option -- d
usage: date [-u] mmddHHMM[[cc]yy][.SS]
date [-u] [+format]
date -a [-]sss[.fff]------------------ ---------- Post updated at 10:24 PM ---------- Previous update was at 08:18 PM ---------- Anyone, please can assist? Last edited by methyl; 03-05-2012 at 12:18 PM.. Reason: code tags |
|
#4
|
||||
|
||||
|
Looks like your installation of date doesn't support -d option. 1. Please mention your OS and shell. 2. Do you want it only in unix or is perl ok? Code:
$ # Three days in future $ perl -e '$x=localtime(time+(3*86400));print $x' Thu Mar 8 03:53:00 2012 $ # Three days in past $ perl -e '$x=localtime(time+(-3*86400));print $x' Fri Mar 2 03:53:33 2012 $ |
| Sponsored Links | |
|
|
#5
|
||||
|
||||
|
Code:
$ AFTER_TWO_DAYS=`TZ="GMT-48" date +'%m/%d/%Y'` $ echo $AFTER_TWO_DAYS 03/07/2012 |
| Sponsored Links | |
|
|
#6
|
||||
|
||||
|
Using Korn shell 93 (ksh93) Code:
$ FUTURE=$(printf "%T" "now + 3 days") $ echo $FUTURE Thu Mar 8 12:19:57 EST 2012 |
| Sponsored Links | |
|
|
#7
|
|||
|
|||
|
@amit.mathur08
Please post what Operating System and version you have and what Shell you are using. It would help to know what you are going to do with this future date field in case there is another approach. @itkamaraj Beware of the TZ method. On most O/S it does not work for values above 24 hours and it is only reliable 7/24 when the local timezone is GMT without Daylight Saving Time. |
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Delete a row from a file if one column containing a date is greater than the current system date | chumsky | UNIX for Dummies Questions & Answers | 4 | 07-06-2011 02:07 AM |
| Number of days between the current date and user defined date | hiten.r.chauhan | Shell Programming and Scripting | 1 | 03-01-2011 09:13 AM |
| Date after 5 days from current date in YYYYMMDD format | needyourhelp10 | Shell Programming and Scripting | 8 | 09-30-2010 04:33 PM |
| How to find a date which is 7 days past when given current date | ladtony | Shell Programming and Scripting | 17 | 04-09-2009 04:06 PM |
| Perl: Extracting date from file name and comparing with current date | MKNENI | Shell Programming and Scripting | 4 | 03-26-2008 04:01 PM |
|
|