Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Batch script variable that refers to previous business day?

209 views
Skip to first unread message

Marcus Leon

unread,
Feb 28, 2005, 10:46:18 AM2/28/05
to
Does anyone know how to create a batch script variable that contains a
string representing the previous business day?

I know how to get the current day but I have no idea how to do the DOS
date arithmetic to get the previous day.

Thanks

Marcus.

Timo Salmi

unread,
Feb 28, 2005, 11:58:30 AM2/28/05
to

The straight yesterday problem is covered e.g. in

250909 Oct 12 2004 ftp://garbo.uwasa.fi/pc/link/tsbat.zip
tsbat.zip Useful MS-DOS batch files and tricks, T.Salmi

111572 Jan 22 2005 ftp://garbo.uwasa.fi/pc/link/tscmd.zip
tscmd.zip Useful NT/2000/XP script tricks and tips, T.Salmi

But, of course, it is not that simple since one has to test whether
yesterday was Saturday or Sunday and step back accordingly. Getting
a weekday is covered in the same material, though.

However, holidays change in each year and even country. Taken to the
very exact limits your task would be far too complicated for common
batching.

All the best, Timo

--
Prof. Timo Salmi ftp & http://garbo.uwasa.fi/ archives 193.166.120.5
Department of Accounting and Business Finance ; University of Vaasa
mailto:t...@uwasa.fi <http://www.uwasa.fi/~ts/> ; FIN-65101, Finland
Timo's FAQ materials at http://www.uwasa.fi/~ts/http/tsfaq.html

Ted Davis

unread,
Feb 28, 2005, 4:30:10 PM2/28/05
to
On 28 Feb 2005 07:46:18 -0800, "Marcus Leon" <marcu...@gmail.com>
wrote:

It's actually simple if you can insure that the program will be run
exactly once *every* business day and no others: two files - one
contains the last date and one contains today's.

Copy the last day file to a working file and save today's date back to
it. The working file then contains the date of the last day the
program was run.

Since methods for preventing multiple runs of the progrm on the same
day are operating system specific, posted to so many groups serving
som many different operating systems, and didn't identify the OS of
actual interest, I have to omit any suggestions of how to do that as
probably being off topic in most of the groups.


T.E.D. (tda...@gearbox.maem.umr.edu)
SPAM filter: Messages to this address *must* contain "T.E.D."
somewhere in the body or they will be automatically rejected.

Dr John Stockton

unread,
Feb 28, 2005, 4:32:00 PM2/28/05
to
JRS: In article <1109605578.2...@f14g2000cwb.googlegroups.com>,
dated Mon, 28 Feb 2005 07:46:18, in news:comp.os.ms-windows.nt.admin.misc,
comp.os.msdos.programmer,comp.os.ms-windows.misc, Marcus Leon
<marcu...@gmail.com> posted :

Yes, NOWMINUS, via sig line 3, using options D1 Z15, will get to firstly
yesterday and then to Fri from Sat/Sun.

Of course, you've not given your location; you'll have to adjust that a
bit more if you work in Tel Aviv or Riyadh - offset a day or two before
Z15, then remove offset.

Then there's the question of do business days include holidays?

Christmas Day is fixed, but its associated holidays can move.

Knowing the year, NOWMINUS can calculate the dates of most holidays; and
its friend ENVICALC can, by EASTER.SCR, get Easter Sunday ...; if you're
in Riyadh or Tel Aviv, though ...........

OTOH, with NT or other Windows>3, you can use WSH and do it in VBScript -
see via sig line 2.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk DOS 3.3, 6.20; Win98. ©
Web <URL:http://www.merlyn.demon.co.uk/> - FAQqish topics, acronyms & links.
PAS EXE TXT ZIP via <URL:http://www.merlyn.demon.co.uk/programs/00index.htm>
My DOS <URL:http://www.merlyn.demon.co.uk/batfiles.htm> - also batprogs.htm.

Dr John Stockton

unread,
Mar 1, 2005, 6:53:39 AM3/1/05
to
JRS: In article <dd2721diaidnbnrob...@4ax.com>, dated
Mon, 28 Feb 2005 15:30:10, seen in news:comp.os.msdos.programmer, Ted
Davis <tda...@gearbox.maem.umr.edu> posted :

>On 28 Feb 2005 07:46:18 -0800, "Marcus Leon" <marcu...@gmail.com>
>wrote:
>
>>Does anyone know how to create a batch script variable that contains a
>>string representing the previous business day?
>>
>>I know how to get the current day but I have no idea how to do the DOS
>>date arithmetic to get the previous day.
>
>It's actually simple if you can insure that the program will be run
>exactly once *every* business day and no others: two files - one
>contains the last date and one contains today's.

It's not insurance that is needed, but ensurance.

The files do not need to contain the dates; resources are saved if they
do not contain anything at all, being 0 bytes long. The directory dates
suffice.

>Copy the last day file to a working file and save today's date back to
>it. The working file then contains the date of the last day the
>program was run.

Delete the older file (by name); rename the newer (by name) to the
older; create a new empty file. IIRC, rem > today.dat does it, and
programs can do it with ease.

>Since methods for preventing multiple runs of the progrm on the same
>day are operating system specific, posted to so many groups serving
>som many different operating systems, and didn't identify the OS of
>actual interest, I have to omit any suggestions of how to do that as
>probably being off topic in most of the groups.

Only details are specific. Allow the program to be run at any time; but
make its first act be to see if the "today" file is of today's date,
and, if so, to present a suitable remark and abort. Otherwise,
immediately or at successful completion, it does the update sequence.


H'mmm - it's simpler than that. Read the date of the single marker
file. If that's today, abort; otherwise, that's the date of business-
yesterday; at a suitable stage in the processing, overwrite the marker
file.


But to ensure that a program is run once on each business day is
impractical - what if the computer PSU fails, and takes 24h to get
replaced? Does one declare a holiday? The date of processing should
not be too firmly coupled to the date of the data.

Ted Davis

unread,
Mar 1, 2005, 4:46:44 PM3/1/05
to
On Tue, 1 Mar 2005 11:53:39 +0000, Dr John Stockton
<sp...@merlyn.demon.co.uk> wrote:

>JRS: In article <dd2721diaidnbnrob...@4ax.com>, dated
>Mon, 28 Feb 2005 15:30:10, seen in news:comp.os.msdos.programmer, Ted
>Davis <tda...@gearbox.maem.umr.edu> posted :
>>On 28 Feb 2005 07:46:18 -0800, "Marcus Leon" <marcu...@gmail.com>
>>wrote:
>>
>>>Does anyone know how to create a batch script variable that contains a
>>>string representing the previous business day?
>>>
>>>I know how to get the current day but I have no idea how to do the DOS
>>>date arithmetic to get the previous day.
>>
>>It's actually simple if you can insure that the program will be run
>>exactly once *every* business day and no others: two files - one
>>contains the last date and one contains today's.
>
>It's not insurance that is needed, but ensurance.

A Brit language snob, I see.

>
>The files do not need to contain the dates; resources are saved if they
>do not contain anything at all, being 0 bytes long. The directory dates
>suffice.

I'm reading this in a DOS group - in DOS it would typically be done by
making the file a batch file to SET an environment variable - you are
recommending a Windows NT, possible W2K/XP, specific solution in a DOS
group. You are off topic.

<snip>


>
>>Since methods for preventing multiple runs of the progrm on the same
>>day are operating system specific, posted to so many groups serving
>>som many different operating systems, and didn't identify the OS of
>>actual interest, I have to omit any suggestions of how to do that as
>>probably being off topic in most of the groups.
>
>Only details are specific. Allow the program to be run at any time; but
>make its first act be to see if the "today" file is of today's date,
>and, if so, to present a suitable remark and abort. Otherwise,
>immediately or at successful completion, it does the update sequence.

That" *hard* in DOS. Practical in the the Windows NT series, but more
difficult than reading the contents of the file or having it a batch
file.


>
>
>H'mmm - it's simpler than that. Read the date of the single marker
>file. If that's today, abort; otherwise, that's the date of business-
>yesterday; at a suitable stage in the processing, overwrite the marker
>file.

More Windows dribble in a DOS group.


>
>
>But to ensure that a program is run once on each business day is
>impractical - what if the computer PSU fails, and takes 24h to get
>replaced? Does one declare a holiday? The date of processing should
>not be too firmly coupled to the date of the data.

It's obvious that fixing the PC requires manual intervention, as does
dealing with the tasks normally done on the broken machine - it's not
too far a streatch to suggest that in emergencies, a manual
intervention in the dat data is also appropriate.

I have *got* to remember to put you back in my twit filters.

Klaus Meinhard

unread,
Mar 2, 2005, 3:22:28 AM3/2/05
to
Marcus Leon wrote:

Since 4DOS is now freeware, and has excellent date computing
capabilities, I recommend a 4DOS solution:

You can easily check the date you're looking for with a SWITCH / CASE
construct like

SWITCH %@dowi[%mydate]
:: returns an integer for the day of the week, starting with 1 for
sunday
CASE 1 .OR. 7
Do something like decreasing %mydate
DEFAULT
Do the thing
ENDSWITCH

If you really want to exclude all holidays you can use any method from
automatically computing most holidays to a look-up table to compare the
date against (there's a batch called XCALAE in my 4XBTM collection,
available via my sig, which is a batch calendar which computes all
Easter- _and_ all Christmas-dependant holidays.)

Using 4DOS, this really becomes a starightforward and easy to solve
little problem.

--
* Klaus Meinhard *
www.4dos.info
- 4DOS Info -
- Info for DOS -

Dr John Stockton

unread,
Mar 2, 2005, 10:54:29 AM3/2/05
to
JRS: In article <8tn921l16csspmeid...@4ax.com>, dated
Tue, 1 Mar 2005 15:46:44, seen in news:comp.os.msdos.programmer, Ted

Davis <tda...@gearbox.maem.umr.edu> posted :
>On Tue, 1 Mar 2005 11:53:39 +0000, Dr John Stockton
><sp...@merlyn.demon.co.uk> wrote:
>
>>JRS: In article <dd2721diaidnbnrob...@4ax.com>, dated
>>Mon, 28 Feb 2005 15:30:10, seen in news:comp.os.msdos.programmer, Ted
>>Davis <tda...@gearbox.maem.umr.edu> posted :
>>>On 28 Feb 2005 07:46:18 -0800, "Marcus Leon" <marcu...@gmail.com>
>>>wrote:
>>>
>>>>Does anyone know how to create a batch script variable that contains a
>>>>string representing the previous business day?
>>>>
>>>>I know how to get the current day but I have no idea how to do the DOS
>>>>date arithmetic to get the previous day.
>>>
>>>It's actually simple if you can insure that the program will be run
>>>exactly once *every* business day and no others: two files - one
>>>contains the last date and one contains today's.
>>
>>It's not insurance that is needed, but ensurance.
>
>A Brit language snob, I see.

No : before I criticise Americans for their incorrect use of what they
consider to be English, I consult Webster, in a reasonably large
edition, to determine whether the error is individual or collective.
You are wrong in terms of what your people fondly consider to be a
dictionary of English. You are also wrong according to COD and
Chambers'. You are just plain wrong. One expects even US academics to
be able to get common words right - or, at least, one feels that they
should do so. It is necessary for accurate communication of meaning;
that is why some politicians tend to avoid it, and others mumble.

Example added to <URL:http://www.merlyn.demon.co.uk/mail-use.htm#SE>.


>>The files do not need to contain the dates; resources are saved if they
>>do not contain anything at all, being 0 bytes long. The directory dates
>>suffice.
>
>I'm reading this in a DOS group - in DOS it would typically be done by
>making the file a batch file to SET an environment variable - you are
>recommending a Windows NT, possible W2K/XP, specific solution in a DOS
>group. You are off topic.

It can be done with SET in a Windows DOS box, for the life of the box;
and it can also be done with a zero-length file in DOS proper.
Moreover, this article is cross-posted to Windows groups; thus all such
classes of solution are on-topic in at least one group. Perhaps you
need a kill-rule on "windows" in the newsgroups line.

If the OP's machine is ever turned off, a SET approach is unlikely to be
of much use to him.


><snip>
>>
>>>Since methods for preventing multiple runs of the progrm on the same
>>>day are operating system specific, posted to so many groups serving
>>>som many different operating systems, and didn't identify the OS of
>>>actual interest, I have to omit any suggestions of how to do that as
>>>probably being off topic in most of the groups.
>>
>>Only details are specific. Allow the program to be run at any time; but
>>make its first act be to see if the "today" file is of today's date,
>>and, if so, to present a suitable remark and abort. Otherwise,
>>immediately or at successful completion, it does the update sequence.
>
>That" *hard* in DOS.

????????????????????? I wonder what that was meant to be?

> Practical in the the Windows NT series, but more
>difficult than reading the contents of the file or having it a batch
>file.

You are posting without understanding. I wrote "program", meaning
"program" not "script". A program can easily do such things - and you
are reading an article posted to a DOS programmer newsgroup.

The OP wrote only in terms of a batch script; you introduced the term
"progrm".

>>H'mmm - it's simpler than that. Read the date of the single marker
>>file. If that's today, abort; otherwise, that's the date of business-
>>yesterday; at a suitable stage in the processing, overwrite the marker
>>file.
>
>More Windows dribble in a DOS group.

Probably you mean "drivel" - it is a pithier word.

At least your lack of understanding is consistent and unaffected by
possible intervening thought processes.

In DOS, the date of a named file can easily be put into an environment
variable by using the normal sort of third-party tools. I can do it
with dir and MiniTrue, so dir and SED should suffice; but I normally use
HUNT, COLS, and STOW. It should be possible with pure DOS; after dir
and FIND, the situation matches that of getting the current date using
an auxiliary file current.bat.


>>But to ensure that a program is run once on each business day is
>>impractical - what if the computer PSU fails, and takes 24h to get
>>replaced? Does one declare a holiday? The date of processing should
>>not be too firmly coupled to the date of the data.
>
>It's obvious that fixing the PC requires manual intervention, as does
>dealing with the tasks normally done on the broken machine - it's not
>too far a streatch to suggest that in emergencies, a manual
>intervention in the dat data is also appropriate.

Stretch. dat? One should always re-read what one intends
to publish, in case others read the published version.

Indeed. But the OP should allow for it in his system design, so that
the manual intervention is easy and risk-free. He could arrange that
the calculated date was a default, that one could override by a
parameter ...


>I have *got* to remember to put you back in my twit filters.

It would be a pity if your limited abilities were never increased by
careful reading of material posted by your betters; there are so many of
them.

And, if your judgement were correct, would that not be an unprofessional
act? You appear to be posting during working hours; it should therefore
be your duty to correct, to the limit of your ability, what you consider
to be incorrect. If you're not working at umr.edu, then you should use
an "Organization" line adequate to override the presumed affiliation.

Julie Warden

unread,
Mar 2, 2005, 1:40:55 PM3/2/05
to

Marcus,

You may want try using a little AWK script with a datefile. AWK for
Windows or DOS is a little freeware program easily downloaded. Here's
the link for the Windows version:
http://gnuwin32.sourceforge.net/packages/gawk.htm

What I would do is create file containing all business days for your
company. This will handle the problems of company specific holidays,
such as the day after Thanksgiving, which is often granted in the U.S.
You have to be sure that the file wraps at least 1 day, in that it
must contain yesterday whenever you run it, and should go past the end
of the year to handle when you refresh the file.

Name this file something like "datefile.txt" or "businessdays.txt" and
run this AWK script against it. I called it date.awk:

BEGIN { "date /t" | getline;
today = $2;
lastdate = "";
}

{ if (today == $1) print lastdate;lastdate = $1 }

Here's the little date file I created to test it with called
datefile.txt:
02/25/2005
02/28/2005
03/01/2005
03/02/2005

Then the command line is:
awk -f date.awk datefile.txt

The output is yesterday's date in MM/DD/YYYY format, which you pipe to
your application. I hope this helps.

Regards,
Julie

Ted Davis

unread,
Mar 2, 2005, 4:44:26 PM3/2/05
to

This is posted to a DOS group and that is NT specific - gawk has a
very useful strftime() function that is OS independent ... if a DOS
version exists.

Message has been deleted

Harry

unread,
Mar 3, 2005, 12:18:52 AM3/3/05
to
Marcus Leon wrote...


Get yesterday.bat from http://www.robvanderwoude.com/datetiment.html

C:\> yesterday.bat
Format: YYYYMMDD (DD/MM/YYYY)
==================================
Today: 20050302 (02/03/2005)
Yesterday: 20050301 (01/03/2005)

0 new messages