Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date command 1

Status
Not open for further replies.

anatazi

Programmer
Jun 24, 2002
33
0
0
US
Is there a way to get the date command to display yesterday's day of the week either in numbers[1,7] or words?
Thanks
 
If you are using Linux (and possibly others?) there's also a handy feature that lets you specify how long ago you want the date from:

[tt]date +"%u" --date "1 day ago"[/tt] Annihilannic.
 
N.B If it's Sunday (i.e. date +%u gives 0) then -1 will give -1, not 6 (for Saturday).
Just a caveat. Dickie Bird (:)-)))
 
Hi again,
I tried running the echo $[(`date +"%u"`-1+7)%7]

and got syntax error: `(' unexpected
Any ideas why?
Thanks
 
I am using an interactive Bourne shell (sh)
 
I have just changed it permanently to ksh and it still gives the same error.
 
I did, and i still get the same message.syntax error: `(' unexpected
Thanks
 
how about
Code:
echo $((($(date +"%u") +6)%7))
?
 
I am putting a script together with the following:

DateFinish=`date '+"20%y/%m/%d 23:59 GMT"'`

which sets DateFinish to todays date in a specific format,
what would the syntax be to set DateFinish to tommorows date?

 
What operating system?

[tt]DateFinish=`date '+"20%y/%m/%d 23:59 GMT"' --date "1 day"`[/tt]

Should do it on Linux or anything with a recent GNU date utility.

Otherwise, perhaps a quick C programme:

[tt]#include <sys/types.h>
#include <time.h>

struct tm *tm_thetime;
time_t thetime;
char cbuf[1024];

int main(void) {
time(&thetime);
tm_thetime = localtime(&thetime);
tm_thetime->tm_mday++;
mktime((struct tm *)&tm_thetime);
strftime(cbuf,1024,&quot;%y/%m/%d&quot;,tm_thetime);
printf(&quot;%s\n&quot;,cbuf);
}[/tt] Annihilannic.
 
And just to give you another option:

TZ=aaa24 date +%u
6

or as alphabetic:

TZ=aaa24 date +%a
Sat
TZ=aaa24 date +%A
Saturday
 
The C programme is shorter in PERL, as usual:

[tt]#!/usr/bin/perl -w
use POSIX;
@now = localtime(time);
$now[3]++; # Increment mday.
mktime(@now); # Sanity check tm structure.
print strftime(&quot;%y/%m/%d\n&quot;,@now);[/tt] Annihilannic.
 
re: <<I am putting a script together with the following:
DateFinish=`date '+&quot;20%y/%m/%d 23:59 GMT&quot;'`
which sets DateFinish to todays date in a specific format,
what would the syntax be to set DateFinish to tommorows date?>>

ended up using:

DateFinish=`date '+&quot;20%y/%m/'`$((`date +&quot;%d&quot;`+1))`echo &quot; 23:59 GMT&quot;'&quot;`

This works on Solaris 5.8

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top