Hi guys,
I need to find tomorrows date in date fomat and should be in variable.
as I need to grep this date in a flat file
ie. if today's date is '09 JAN 2009'
output should be '10 JAN 2009'
unix/perl script will be fine.
Hi guys,
I need to find tomorrows date in date fomat and should be in variable.
as I need to grep this date in a flat file
ie. if today's date is '09 JAN 2009'
output should be '10 JAN 2009'
unix/perl script will be fine.
date | awk '{print $1,$2,$3 + 1,$4}'
From....
simon@cartman:~$ date
Fri Jan 9 15:09:45 GMT 2009
simon@cartman:~$ date | awk '{print $1,$2,$3 + 1,$4}'
Fri Jan 10 15:09:46
simon@cartman:~$
Just realised....You would of course have to wrap this in a if statement to ensure the dates, months, years roll.
A better way would be to increment the unix time stamp by the correct integer (seconds in 24 hours), and then convert to the normal date.
Thanks for your quick reply
I am gettting the output as
Fri Jan 10 10:16:39 -- 10th Jan is SAT
but i need
10 Jan 2009 format.
myvar=`date '+%d %b %Y' --date="next day"`
echo $myvar
myvar=`date '+%d %b %Y' --date='1 days'`
echo $myvar
myvar=`date '+%d %b %Y' --date="tomorrow"`
echo $myvar
myvar=` date '+%d %b %Y' --date="-1 days ago"`
echo $myvar
If you have GNU date:
$ date --version
date (coreutils) 5.2.1
Written by David MacKenzie.
Copyright (C) 2004 Free Software Foundation, Inc.
$ date -d 'tomorrow' +'%d %b %Y'
10 Jan 2009
Hello All,
'snoop2048' solutions is working after some changes.
`date | awk '{print $3 + 1,$2,$6}'`
Thank you all for your quick response. Appreciated !!!
Have a great Weekend !!!
Wont work on last day of month:
# date -d "2008-01-31" | awk '{print $3 + 1,$2,$6}'
32 Jan 2008
ohhhhh no
Ya, you are right. I missed out that.
thanks.
I am not sure why the solutions given by 'Ikon' is not working. if i execute the script, it's returning the same date
#!/bin/ksh/
#myvar=`date '+%d %b %Y' --date="tomorrow"`
#myvar=`date '+%d %b %Y' --date='-1 days ago'`
myvar=`date '+%d %b %Y' --date="next day"`
echo $myvar
output is 09 JAN 2009
Also, if I used solution of 'SFYNC', i am getting following error
date: illegal option -- d
usage: date [-u] mmddHHMM[[cc]yy][.SS]
date [-u] [+format]
date -a [-]sss[.fff]
Please advise.
You are not using gnu date, your version does not support --date.
Try this:
TZ=EDT-24 date +"%d %b %Y"
Hi Ikon,
I am getting below output. How can I remove 'US/Eastern; word from the next line. Also could you please explain the code ?
TZ=EDT-24 date +"%d %b %Y"
echo $TZ
OUTPUT
10 Jan 2009
US/Eastern
It works kinda weird, IMO.
TZ=EDT-24 adds 24hours to the time
TZ=EDT+24 Removed 24hours
You probabally want to change TZ to what your time zone actually is.
I dont fully understand how it works. Because +1 doesnt add or subtract 1 hour.
Hi Ikon,
Actually I don't want time zone itself. I need only 'dd mon yyyy'
If you have Perl and the Date::Manip module installed:
date +'%Y%m%d'|perl -ne'use Date::Manip;print UnixDate(DateCalc(ParseDate($_),"tomorrow"),"%d %b %Y\n")'
10 Jan 2009
Hi SFYNC,
I think Date::Manip module has not been installed.
I am getting following error
Can't locate Date/Manip.pm in @INC
This is what I use to get tomorrrows date....
TZ=CST-24 date +"%m %d %Y"
Try entering this command to see what Perl modules you have installed:
perl -MFile::Find=find -MFile::Spec::Functions -Tlwe'find {wanted=>sub {print canonpath $_ if /\.pm\z/},no_chdir=>1},@INC'
The output can be quite a few lines so I'd redirect it to a file or pipe it through more. You can also pipe it through grep to look for specific names:
perl -MFile::Find=find -MFile::Spec::Functions -Tlwe'find {wanted=>sub {print canonpath $_ if /\.pm\z/},no_chdir=>1},@INC'|grep Date
Bob Stockler's datemath is a collection of quite useful shell scripts for date manipulations.
Pick it up from my ftp site, ftp.jpr.com.
To manipulate dates, you should always use a standard format, preferably ISO YYYY-MM-DD, and use a function to convert it to other formats after doing any date arithmetic.
I have a library of shell functions for manipulating dates at The Dating Game.
. date-funcs
dateshift 2009-01-09 +1