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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

please, how to get the date yesterday working day.

Status
Not open for further replies.

hok1man

Technical User
Feb 16, 2008
102
Hi guys,

I got an issue to find yesterday working day,
the working days is mon - fri,

so if today is monday 20080929, i need to get yesterday working days which is friday 20080926.

in linux GNU there is date --date'1 day ago', but now in UNIX there's no such thing...

can you guys help please ?

Thanks guys,


 
Thanks Anni,

what about if yesterday from specified date,
your script is only for yesterday from current date.
 
Well, you could use this variation:

Code:
#!/usr/bin/perl -w
use POSIX;
print strftime "%d/%m/%Y\n",localtime mktime(0,0,0,$ARGV[0]+$ARGV[3],$ARGV[1]-1,$ARGV[2]-1900);

You can use it to calculate the date offset by any amount from any date, e.g.

Code:
$ ./diffdate.pl 29 09 2008 0
29/09/2008
$ ./diffdate.pl 29 09 2008 +10
09/10/2008
$ ./diffdate.pl 29 09 2008 -10
19/09/2008
$ ./diffdate.pl 29 09 2008 -1
28/09/2008


Annihilannic.
 
Or

DATE_STAMP=`TZ=GMT+24 date +%A" "%Y%m%d`

Replace CST with your own TZ E.g. GMT

Mike

"Whenever I dwell for any length of time on my own shortcomings, they gradually begin to seem mild, harmless, rather engaging little things, not at all like the staring defects in other people's characters."
 
If you have a recent version of ksh93
Code:
#!/usr/bin/ksh93
#
# print date of previous working day
#

# last working day in week
lastwd="Friday"

integer now=$(printf "%(%w)T\n")
if (( now > 1 ))
then
    printf "%(%a %Y-%m-%d)T\n" "yesterday"
else
    printf "%(%a %Y-%m-%d)T\n" "last $lastwd"
fi
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top