Finding yesterdays date

Hi can anyone tell how we can find yesterdays date using shell ??

thanks in advance
Anup V [ Mo, 03 Dezember 2007 07:53 ] [ ID #1884282 ]

Re: Finding yesterdays date

On 2007-12-03, varkey <anupvarghese [at] gmail.com> wrote:
>
>
> Hi can anyone tell how we can find yesterdays date using shell ??
>
> thanks in advance
date -d yesterday (if you have GNU date)
Or add this to your crontab:
59 23 * * * date > yesterday
Bill Marcum [ Mo, 03 Dezember 2007 08:19 ] [ ID #1884283 ]

Re: Finding yesterdays date

On 3 Dec, 07:19, Bill Marcum <marcumb... [at] bellsouth.net> wrote:
> date -d yesterday (if you have GNU date)
> Or add this to your crontab:
> 59 23 * * * date > yesterday

Or if you have expect, try:

expect -c 'puts [clock format [clock scan yesterday] -format %m/%d/
%y]'

- adjust the format string to taste, see details at
http://home.houston.rr.com/brianohagan/tcl_tk_ref_guide.html #Clock
colin.macleod [ Mo, 03 Dezember 2007 10:53 ] [ ID #1884285 ]

Re: Finding yesterdays date

In article <slrnfl7bgs.6iv.marcumbill [at] lark.localnet>,
Bill Marcum <marcumbill [at] bellsouth.net> wrote:
>On 2007-12-03, varkey <anupvarghese [at] gmail.com> wrote:
>>
>>
>> Hi can anyone tell how we can find yesterdays date using shell ??
>>
>> thanks in advance
>date -d yesterday (if you have GNU date)
>Or add this to your crontab:
>59 23 * * * date > yesterday

Or:

gawk 'BEGIN {print strftime("%c",systime()-86400)}'

Someone will probably come up with a Perl solution...
gazelle [ Mo, 03 Dezember 2007 10:58 ] [ ID #1884286 ]

Re: Finding yesterdays date

On Dec 3, 12:53 am, varkey <anupvargh... [at] gmail.com> wrote:
> Hi can anyone tell how we can find yesterdays date using shell ??
>
> thanks in advance

ruby -r date -e 'puts (Date.today - 1)'
William James [ Mo, 03 Dezember 2007 11:14 ] [ ID #1884287 ]

Re: Finding yesterdays date

In news:527e1fa4-c97c-4e0e-9cf1-8c0d15b394b2 [at] l16g2000hsf.google groups.com,
William James <w_a_x_man [at] yahoo.com> wrote:

>> Hi can anyone tell how we can find yesterdays date using shell ??
>
> ruby -r date -e 'puts (Date.today - 1)'

mktime -d -1

using http://www.weirdways.com/technogeek/source/mktime the best, most
versatile and intuitive tool I've found for manipulating date values.
Gretch [ Mo, 03 Dezember 2007 12:35 ] [ ID #1884290 ]

Re: Finding yesterdays date

On Mon, 3 Dec 2007 02:14:57 -0800 (PST), William James wrote:
> On Dec 3, 12:53 am, varkey <anupvargh... [at] gmail.com> wrote:
>> Hi can anyone tell how we can find yesterdays date using shell ??
>>
>> thanks in advance
>
> ruby -r date -e 'puts (Date.today - 1)'
[...]

ksh93 -c 'printf "%T\n" yesterday'

--
Stephane
Stephane CHAZELAS [ Mo, 03 Dezember 2007 12:39 ] [ ID #1884291 ]

Re: Finding yesterdays date

On 03 Dec 2007 11:39:40 GMT, Stephane Chazelas wrote:
[...]
> ksh93 -c 'printf "%T\n" yesterday'

zsh -c 'zmodload zsh/datetime
strftime %c $((EPOCHSECONDS-86400))'

--
Stephane
Stephane CHAZELAS [ Mo, 03 Dezember 2007 12:41 ] [ ID #1884292 ]

Re: Finding yesterdays date

create this Perl script:

-----
#!/usr/bin/perl
# simulate gnu "date --date '1 day ago'
#
use Getopt::Std;
getopt('d');
if ($opt_d){
use Time::Local;
my ($ctime) = time;
$ctime -= $opt_d*24*60*60;
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
localtime($ctime);
printf("%04i%02i%02i\n", $year+1900, $mon+1, $mday);
} else {
print "No flag received. Usage:\n";
print "daysago.pl -d [no. of days]\n";
}
-----

- then run it with:
$ ./daysago.pl -d 1

where 1 is the number of days you want to go back in time ....
thomasriise [ Mo, 03 Dezember 2007 14:25 ] [ ID #1884294 ]

Re: Finding yesterdays date

On 3 Dic, 14:25, thomasriise <thomasri... [at] gmail.com> wrote:
> create this Perl script:
>
> -----
> #!/usr/bin/perl
> # simulate gnu "date --date '1 day ago'
> #
> use Getopt::Std;
> getopt('d');
> if ($opt_d){
> use Time::Local;
> my ($ctime) = time;
> $ctime -= $opt_d*24*60*60;
> my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
> localtime($ctime);
> printf("%04i%02i%02i\n", $year+1900, $mon+1, $mday);} else {
>
> print "No flag received. Usage:\n";
> print "daysago.pl -d [no. of days]\n";}
>
> -----
>
> - then run it with:
> $ ./daysago.pl -d 1
>
> where 1 is the number of days you want to go back in time ....

This is a good script di add or remove days from date:
#!/bin/ksh
#
# Reldate: Calculate a date relative to a given date.
#
# T. Hofmann w... [at] chbs.ciba.com 1994-09-19
#
# Synopsis: reldate <year> <month> <day> <delta>
#
# Reldate adds <delta> days to the specified date and determines
# the resulting date.
#
# Examples: reldate 1999 12 31 1 --> 2000-1-1
# reldate 1996 4 1 -32 --> 1996-2-29
#
# Diagnostics: Only the Gregorian Calendar is supported
# (effective date: Oct. 15, 1582 in then catholic
# countries, otherwise differing, later dates).
#
# Bug: Reldate produces wrong results for given or resulting dates
# before March 1, 1 B.C. (equals "0 A.D."), Gregorian Calendar.

if (($#!=4))
then SNPS="`basename $0` <year> <month> <day> <delta>"
print "Usage: $SNPS" >&2 ; exit 1
else typeset -i YEAR=$1 MONTH=$2 DAY=$3 DELTA=$4
fi

if ((MONTH<3)) ; then let YEAR-=1 MONTH+=9 ; else let MONTH-=3 ; fi
let DD=D=YEAR*365+YEAR/4-YEAR/100+YEAR/400+\(MONTH*367+7\)/
12+DAY-1+DELTA
let DD-=\(D+1\)/146097 DD+=DD/36524 DD-=\(DD+1\)/1461 YEAR=DD/365
let DOY=D-YEAR*365-YEAR/4+YEAR/100-YEAR/400
let MONTH=\(DOY*12+4\)/367 DAY=DOY+1-\(MONTH*367+7\)/12
if ((MONTH>9)) ; then let YEAR+=1 MONTH-=9 ; else let MONTH+=3 ; fi

print "$YEAR-$MONTH-$DAY" # ISO date notation
patrick [ Mo, 03 Dezember 2007 15:19 ] [ ID #1884297 ]

Re: Finding yesterdays date

>>>>> "varkey" == varkey <anupvarghese [at] gmail.com> writes:

varkey> Hi can anyone tell how we can find yesterdays date using shell ??

I've offered this before, but here it is:

YESTERDAY="`date`"
sleep 86400
echo "it was $YESTERDAY yesterday"

Fouls up on DST boundaries, but close enough for most uses.

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn [at] stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
merlyn [ Mo, 03 Dezember 2007 17:16 ] [ ID #1884299 ]

Re: Finding yesterdays date

>>>>> "thomasriise" == thomasriise <thomasriise [at] gmail.com> writes:

thomasriise> create this Perl script:

You get points for doing this the hard way, even with Perl.

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn [at] stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
merlyn [ Mo, 03 Dezember 2007 17:17 ] [ ID #1884300 ]

Re: Finding yesterdays date

At 2007-12-03 08:25AM, "thomasriise" wrote:
> create this Perl script:
>
> -----
> #!/usr/bin/perl
> # simulate gnu "date --date '1 day ago'
> #
> use Getopt::Std;
> getopt('d');
> if ($opt_d){
> use Time::Local;
> my ($ctime) = time;
> $ctime -= $opt_d*24*60*60;
> my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
> localtime($ctime);
> printf("%04i%02i%02i\n", $year+1900, $mon+1, $mday);
> } else {
> print "No flag received. Usage:\n";
> print "daysago.pl -d [no. of days]\n";
> }
> -----
>
> - then run it with:
> $ ./daysago.pl -d 1

Or:
perl -MDate::Manip -le 'print UnixDate(ParseDate("yesterday"),"%Y%m%d")'
or
perl -M'Date::Calc q{:all}' -le '
printf "%4d%02d%02d", Add_Delta_Days(Today(), -1)
'

--
Glenn Jackman
"You can only be young once. But you can always be immature." -- Dave Barry
Glenn Jackman [ Mo, 03 Dezember 2007 18:19 ] [ ID #1884306 ]

Re: Finding yesterdays date

On Dec 3, 4:14 am, William James <w_a_x_... [at] yahoo.com> wrote:
> On Dec 3, 12:53 am, varkey <anupvargh... [at] gmail.com> wrote:
>
> > Hi can anyone tell how we can find yesterdays date using shell ??
>
> > thanks in advance
>
> ruby -r date -e 'puts (Date.today - 1)'

The parentheses were superfluous.

ruby -r date -e 'puts Date.today - 1'
William James [ Mo, 03 Dezember 2007 20:22 ] [ ID #1884313 ]

Re: Finding yesterdays date

Glenn Jackman wrote:
> Or:
> perl -MDate::Manip -le 'print UnixDate(ParseDate("yesterday"),"%Y%m%d")'
> or
> perl -M'Date::Calc q{:all}' -le '
> printf "%4d%02d%02d", Add_Delta_Days(Today(), -1)
> '

or

$ perl -le ($d,$d,$d,$d,$m,$y)=localtime(time-86400);$y+=1900;print"$d. $m.$y"'
2.11.2007
--
Best regards | Be nice to America or they'll bring democracy to
Cyrus | your country.
Cyrus Kriticos [ Mo, 03 Dezember 2007 20:25 ] [ ID #1884314 ]

Re: Finding yesterdays date

On Dec 2, 11:53 pm, varkey <anupvargh... [at] gmail.com> wrote:
> Hi can anyone tell how we can find yesterdays date using shell ??
>
> thanks in advance

If you have gawk, then get the current time and subtract 24 hours.

BEGIN{print strftime("%c", systime() - 60*60*24)}

You may want to choose something other than %c.

-Ed

--
(You can't go wrong with psycho-rats.) (http://mi.eng.cam.ac.uk/
~er258)

/d{def}def/f{/Times findfont s scalefont setfont}d/s{11}d/r{roll}d f 2/
m
{moveto}d -1 r 230 350 m 0 1 179{1 index show 88 rotate 4 mul 0
rmoveto}
for /s 12 d f pop 235 420 translate 0 0 moveto 1 2 scale show
showpage
Edward Rosten [ Mo, 03 Dezember 2007 20:56 ] [ ID #1884318 ]

Re: Finding yesterdays date

Cyrus Kriticos wrote:
>
> Glenn Jackman wrote:
>> Or:
>> perl -MDate::Manip -le 'print
>> UnixDate(ParseDate("yesterday"),"%Y%m%d")'
>> or
>> perl -M'Date::Calc q{:all}' -le '
>> printf "%4d%02d%02d", Add_Delta_Days(Today(), -1)
>> '
>
> or
>
> $ perl -le
> ($d,$d,$d,$d,$m,$y)=localtime(time-86400);$y+=1900;print"$d. $m.$y"'
> 2.11.2007

fix:

perl -le '($d,$d,$d,$d,$m,$y)=localtime(time-86400);$y+=1900;print"$d .$m.$y"'

--
Best regards | Be nice to America or they'll bring democracy to
Cyrus | your country.
Cyrus Kriticos [ Mo, 03 Dezember 2007 21:17 ] [ ID #1884319 ]

Re: Finding yesterdays date

In article <a01f92f8-1daa-4734-a53f-933f53eca5ea [at] e10g2000prf.googlegroups.com>,
Edward Rosten <Edward.Rosten [at] gmail.com> wrote:
>On Dec 2, 11:53 pm, varkey <anupvargh... [at] gmail.com> wrote:
>> Hi can anyone tell how we can find yesterdays date using shell ??
>>
>> thanks in advance
>
>If you have gawk, then get the current time and subtract 24 hours.
>
>BEGIN{print strftime("%c", systime() - 60*60*24)}

It's worth pointing out that a common meaning of "yesterday's date" is not the
date of 24 hours ago, but rather the calendar date of the day prior to the
current day. In locales that use DST, those aren't the same thing. By the
latter meaning, all of these "subtract 24 hours" methods will produce incorrect
results during certain periods near the DST transitions, and those that use
similar means for "n days in the past/future" will produce incorrect results
for other times as well.

John
--
John DuBois spcecdt [at] armory.com KC6QKZ/AE http://www.armory.com/~spcecdt/
spcecdt [ Mi, 05 Dezember 2007 02:14 ] [ ID #1885895 ]

Re: Finding yesterdays date

On Dec 3, 5:17 pm, mer... [at] stonehenge.com (Randal L. Schwartz) wrote:

> You get points for doing this the hard way, even with Perl.

Thanks. I use it as an utility for an archive script on solaris. Some
file types I archive x-days back in time, and others xy-days back in
time and so fourth... The datestamp is easily set as a parameter for
these tasks.
thomasriise [ Mi, 05 Dezember 2007 10:44 ] [ ID #1885914 ]

Re: Finding yesterdays date

I live in the CST time zone so I use:
echo "$(TZ=CST+30 date '+%m/%d/%Y %H:%H:%S')

"varkey" <anupvarghese [at] gmail.com> wrote in message
news:09bcd307-8914-4086-98b6-47d233793bd9 [at] d27g2000prf.google groups.com...
> Hi can anyone tell how we can find yesterdays date using shell ??
>
> thanks in advance
Bobby.Higgins [ Sa, 29 Dezember 2007 16:56 ] [ ID #1895493 ]
Linux » comp.unix.shell » Finding yesterdays date

Vorheriges Thema: Re: How to setup a simple shell script? "bad interpreter: No suchfile or directorybin/bash"
Nächstes Thema: Re: How sum 2 arrays in ksh ?