Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers


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 !!

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 03-04-2012
Registered User
 
Join Date: Jun 2010
Posts: 50
Thanks: 0
Thanked 0 Times in 0 Posts
Question Unable to add date to current date.

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  
Old 03-04-2012
Registered User
 
Join Date: Mar 2012
Posts: 14
Thanks: 2
Thanked 2 Times in 2 Posts
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  
Old 03-04-2012
Registered User
 
Join Date: Jun 2010
Posts: 50
Thanks: 0
Thanked 0 Times in 0 Posts
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  
Old 03-04-2012
balajesuri's Avatar
#! /bin/bash
 
Join Date: Apr 2009
Location: India
Posts: 1,626
Thanks: 15
Thanked 458 Times in 442 Posts
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  
Old 03-05-2012
itkamaraj's Avatar
^Kamaraj^
 
Join Date: Apr 2010
Posts: 3,025
Thanks: 33
Thanked 647 Times in 625 Posts

Code:
 
$ AFTER_TWO_DAYS=`TZ="GMT-48" date +'%m/%d/%Y'`
$ echo $AFTER_TWO_DAYS
03/07/2012

Sponsored Links
    #6  
Old 03-05-2012
fpmurphy's Avatar
who?
 
Join Date: Dec 2003
Location: /dev/ph
Posts: 4,452
Thanks: 48
Thanked 364 Times in 336 Posts
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  
Old 03-05-2012
methyl methyl is offline Forum Advisor  
Advisor
 
Join Date: Mar 2008
Posts: 6,388
Thanks: 286
Thanked 668 Times in 640 Posts
@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
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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



All times are GMT -4. The time now is 12:10 AM.