Finding yesterdays date

Finding yesterdays date

am 03.12.2007 07:53:24 von Anup V

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

thanks in advance

Re: Finding yesterdays date

am 03.12.2007 08:19:56 von Bill Marcum

On 2007-12-03, varkey 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

Re: Finding yesterdays date

am 03.12.2007 10:53:18 von colin.macleod

On 3 Dec, 07:19, Bill Marcum 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

Re: Finding yesterdays date

am 03.12.2007 10:58:50 von gazelle

In article ,
Bill Marcum wrote:
>On 2007-12-03, varkey 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...

Re: Finding yesterdays date

am 03.12.2007 11:14:57 von William James

On Dec 3, 12:53 am, varkey wrote:
> Hi can anyone tell how we can find yesterdays date using shell ??
>
> thanks in advance

ruby -r date -e 'puts (Date.today - 1)'

Re: Finding yesterdays date

am 03.12.2007 12:35:05 von Gretch

In news:527e1fa4-c97c-4e0e-9cf1-8c0d15b394b2@l16g2000hsf.google groups.com,
William James 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.

Re: Finding yesterdays date

am 03.12.2007 12:39:40 von Stephane CHAZELAS

On Mon, 3 Dec 2007 02:14:57 -0800 (PST), William James wrote:
> On Dec 3, 12:53 am, varkey 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

Re: Finding yesterdays date

am 03.12.2007 12:41:37 von Stephane CHAZELAS

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

Re: Finding yesterdays date

am 03.12.2007 14:25:00 von thomasriise

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

Re: Finding yesterdays date

am 03.12.2007 15:19:40 von patrick

On 3 Dic, 14:25, 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
>
> 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...@chbs.ciba.com 1994-09-19
#
# Synopsis: reldate
#
# Reldate adds 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` "
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

Re: Finding yesterdays date

am 03.12.2007 17:16:43 von merlyn

>>>>> "varkey" == varkey 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

Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!

Re: Finding yesterdays date

am 03.12.2007 17:17:30 von merlyn

>>>>> "thomasriise" == thomasriise 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

Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!

Re: Finding yesterdays date

am 03.12.2007 18:19:31 von Glenn Jackman

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

Re: Finding yesterdays date

am 03.12.2007 20:22:51 von William James

On Dec 3, 4:14 am, William James wrote:
> On Dec 3, 12:53 am, varkey 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'

Re: Finding yesterdays date

am 03.12.2007 20:25:28 von Cyrus Kriticos

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.

Re: Finding yesterdays date

am 03.12.2007 20:56:43 von Edward Rosten

On Dec 2, 11:53 pm, varkey 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

Re: Finding yesterdays date

am 03.12.2007 21:17:42 von Cyrus Kriticos

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.

Re: Finding yesterdays date

am 05.12.2007 02:14:28 von spcecdt

In article ,
Edward Rosten wrote:
>On Dec 2, 11:53 pm, varkey 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@armory.com KC6QKZ/AE http://www.armory.com/~spcecdt/

Re: Finding yesterdays date

am 05.12.2007 10:44:00 von thomasriise

On Dec 3, 5:17 pm, mer...@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.

Re: Finding yesterdays date

am 29.12.2007 16:56:37 von Bobby.Higgins

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

"varkey" wrote in message
news:09bcd307-8914-4086-98b6-47d233793bd9@d27g2000prf.google groups.com...
> Hi can anyone tell how we can find yesterdays date using shell ??
>
> thanks in advance