home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
DP Tool Club 8
/
CDASC08.ISO
/
VRAC
/
FDATE82A.ZIP
/
FDATE.DOC
< prev
next >
Wrap
Text File
|
1993-08-15
|
107KB
|
2,788 lines
FDATE Version 8.2a August 13, 1993
======================================================================
AUTHOR: Stephen Ferg
5113 N. 8th Road
Arlington, VA 22205-1201
USA
telephone (voice, not FAX): (703) 525-2241
CompuServe ID : 73377,1157
=======================================================================
Table of Contents
Page numbers in the WordPerfect version of FDATE.DOC (which is not
distributed with FDATE) are lost in the conversion to ASCII format.
Nevertheless, these page numbers give you a rough idea of the relative
locations of the different sections.
WHAT IS FDATE?. . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
OTHER UTILITIES NAMED "FDATE". . . . . . . . . . . . . . . . . . . 3
OVERVIEW OF PARAMETERS . . . . . . . . . . . . . . . . . . . . . . 4
OVERVIEW OF FUNCTIONS. . . . . . . . . . . . . . . . . . . . . . . 6
FUNCTIONS: DETAILED DESCRIPTIONS. . . . . . . . . . . . . . . . . . . 8
DATE FORMATTING FUNCTIONS. . . . . . . . . . . . . . . . . . . . . 8
DATE ARITHMETIC FUNCTIONS. . . . . . . . . . . . . . . . . . . . . 9
MONTH DATE ARITHMETIC FUNCTIONS. . . . . . . . . . . . . . . . . . 10
WEEKDAY DATE ARITHMETIC FUNCTIONS. . . . . . . . . . . . . . . . . 11
DATE/TIME COMPARISON FUNCTIONS . . . . . . . . . . . . . . . . . . 12
NUMERIC ARITHMETIC FUNCTIONS . . . . . . . . . . . . . . . . . . . 13
DATE VALIDATION FUNCTION . . . . . . . . . . . . . . . . . . . . . 15
ECHO FUNCTION. . . . . . . . . . . . . . . . . . . . . . . . . . . 16
DATE FORMATS. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
SYMBOL CONVENTIONS . . . . . . . . . . . . . . . . . . . . . . . . 17
PSEUDODATES. . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
INPUT DATE FORMATS. . . . . . . . . . . . . . . . . . . . . . . . . . 19
CALENDAR DATE INPUT FORMATS. . . . . . . . . . . . . . . . . . . . 19
BUSINESS JULIAN DATE INPUT FORMATS . . . . . . . . . . . . . . . . 20
GETTING DATE/TIME A FILE WAS CREATED . . . . . . . . . . . . . . . 21
OUTPUT DATE FORMATS . . . . . . . . . . . . . . . . . . . . . . . . . 22
DAY-OF-WEEK AND MONTH OUTPUT FORMATS . . . . . . . . . . . . . . . 23
MISCELLANEOUS OUTPUT FORMATS . . . . . . . . . . . . . . . . . . . 23
LEAP-YEAR FLAG OUTPUT FORMAT . . . . . . . . . . . . . . . . . . . 24
TIME OUTPUT FORMATS. . . . . . . . . . . . . . . . . . . . . . . . 24
BUSINESS JULIAN DATE OUTPUT FORMATS. . . . . . . . . . . . . . . . 25
ABSOLUTE DATE/TIME OUTPUT FORMATS. . . . . . . . . . . . . . . . . 26
/T: TIME OVERRIDE PARAMETER. . . . . . . . . . . . . . . . . . . . 27
HOW TO PUT FDATE OUTPUT INTO AN ENVIRONMENT VARIABLE. . . . . . . . . 28
CALL A BATCH FILE. . . . . . . . . . . . . . . . . . . . . . . . . 28
USE AN ENVIRONMENT-MANIPULATION UTILITY. . . . . . . . . . . . . . 28
FDATE'S /V PARAMETER . . . . . . . . . . . . . . . . . . . . . . . 29
/V WHEN USING 4DOS, NDOS, AND UMB. . . . . . . . . . . . . . . . . 30
FDATE'S ERROR HANDLING. . . . . . . . . . . . . . . . . . . . . . . . 31
EXAMPLES OF HOW TO USE FDATE. . . . . . . . . . . . . . . . . . . . . 32
:01 Display Fdate output on screen . . . . . . . . . . . . . . . . 32
:02 Redirect FDATE output to a file. . . . . . . . . . . . . . . . 32
:03 Put FDATE output in an environment variable using a batch file 32
:04 Put FDATE output in an environment variable using /V parm. . . 32
:05 Put FDATE output in an environment variable using STRINGS. . . 32
:06 Put FDATE output in an environment variable using GET. . . . . 32
:07 Change a date from one format into another . . . . . . . . . . 32
:11 Find the difference in days between two dates. . . . . . . . . 33
:12 Find the elapsed days/hours/minutes between two date/times . . 33
:13 Time the execution of a piece of software. . . . . . . . . . . 35
:15 Find calendar date corresponding to a "business Julian" date . 37
:16 Set your PC's date to a business julian date . . . . . . . . . 38
:18 Determine if parm %1 contains a valid date . . . . . . . . . . 40
:19 "Roll your own" date format . . . . . . . . . . . . . . . . . 41
:20 Find the 4th Thursday in November (Thanksgiving) . . . . . . . 41
:22 On a date, show what anniversary it is for some event. . . . . 41
:23 Show a list of holidays in a given year. . . . . . . . . . . . 41
:24 Show a list of Federal holidays in a given year. . . . . . . . 41
:25 Determine if a year is valid, and evenly divisible by 4. . . . 42
:30 Compare a file's date to today's date. . . . . . . . . . . . . 42
:32 Display a list of all files that were created/updated today. . 43
:33 Delete files more than X days old (use a batch-file subroutine) 44
:34 Loop through an array of environment variables . . . . . . . . 49
:44 Do something on the last day (or last Friday) of the month . . 50
:45 Get information about the month prior to the current month . . 51
:51 Represent a date in a short (4-byte) format (technique #1) . . 52
:52 Represent a date in a short (4-byte) format (technique #2) . . 53
:53 SetXX.BAT (used in the previous example) . . . . . . . . . . . 55
:54 Customize Fdate for a language of your choice. . . . . . . . . 57
:55 Fergian.BAT (used in the previous example) . . . . . . . . . . 58
:61 DO-ONCE: Run apps when booting for the first time of the day . 60
:62a Run specific software, depending on the day of the week . . . 61
:62b Run specific software, depending on the day of the week . . . 62
:63 Run a program at a specified time later in the day . . . . . . 62
:67 Change a file's name to a name that contains today's date. . . 63
:68 Change a file's name to a name containing an absolute minute . 63
HOW FDATE THINKS ABOUT DATES. . . . . . . . . . . . . . . . . . . . . 64
FDATE'S BUSINESS VIEW OF THE CALENDAR. . . . . . . . . . . . . . . 64
FDATE'S BASE DATE. . . . . . . . . . . . . . . . . . . . . . . . . 64
FDATE'S LEAP YEAR ALGORITHM. . . . . . . . . . . . . . . . . . . . 65
FDATE'S CENTURY-ASSUMPTION ALGORITHM . . . . . . . . . . . . . . . 66
FDATE'S IMPLEMENTATION LIMITS. . . . . . . . . . . . . . . . . . . 66
DISTRIBUTION ISSUES . . . . . . . . . . . . . . . . . . . . . . . . . 67
USE, REGISTRATION, AND DISTRIBUTION OF FDATE . . . . . . . . . . . 67
TECHNICAL SUPPORT FOR FDATE. . . . . . . . . . . . . . . . . . . . 68
WHERE TO FIND THE MOST CURRENT VERSION OF FDATE. . . . . . . . . . 68
UPLOADING FDATE TO ELECTRONIC BULLETIN BOARDS. . . . . . . . . . . 68
DEMONSTRATION BATCH FILES. . . . . . . . . . . . . . . . . . . . . 68
CONTENTS OF THE FDATE.ZIP DISTRIBUTION FILE. . . . . . . . . . . . 68
FDATE REVISION HISTORY . . . . . . . . . . . . . . . . . . . . . . 69
WHAT IS FDATE?
==============
Fdate is a utility for doing date formatting and date arithmetic in DOS
batch files. There are a number of different ways to put FDATE's output
into environment variables. Once this has been done, the environment
variables can be used and manipulated in many ways in the batch file.
FDATE is freeware, or what is technically known as "zero-cost shareware".
There is no requirement to register FDATE in any way. For more details,
see the DISTRIBUTION ISSUES section.
Here are some of the things you can do with FDATE.
retrieve today's date in a variety of formats
place today's date into a file name
reformat dates
Output formats include common American and European formats, or you
can "roll your own" by manipulating environment variables. Month
and weekday names can be produced in several languages (English,
French, German, Spanish).
calculate when certain holidays occur in a given year
do date arithmetic
determine the date N days before/after a given date
compare two dates to determine which is earlier
compare two dates to determine how many days apart they are
determine if a year is a leap year
determine whether a year is evenly divisible by some number
determine what day of the week a date falls on
run certain software only on certain days of the week
retrieve the date/time from the date/timestamp of a file
do simple integer arithmetic (add, subtract, modulus)
calculate the time a piece of software takes to run
convert a calendar date to/from a "business julian" date
OTHER UTILITIES NAMED "FDATE"
=============================
I recently learned that there is another shareware utility named FDATE in
circulation. It is an implementation of the UNIX "touch" utility, and is
used to change the date/time stamp of a file.
Both FDATEs have been in circulation for too long to make it practical to
change the name of either one. All that can be done is to warn you of a
potentially confusing situation.
OVERVIEW OF PARAMETERS
======================
FDATE accepts the following parameters:
/F /A /B /I /O /P /S /N /D /L /V /T
The only parameter that FDATE requires is the function parameter: /F.
If the /F parameter is not present, FDATE displays a help screen.
If you get FDATE's help screen when you don't expect it, you probably
forgot to specify the /F parameter or mistyped it.
Parameters can be in any order and upper or lower case.
Note that although function and format parms are not case sensitive,
they are "text sensitive". If any characters are missing, added, or
mistyped, the parameter will be rejected.
Parameters -- other than /F -- that are required depend on the function
requested with the /F parameter. Unnecessary parameters are simply
ignored.
The next page contains a brief description of what each of the parameters
means.
/F requests a particular FDATE function. This is Fdate's most important
parameter. See the OVERVIEW OF FUNCTIONS section, and the detailed
description of each Fdate function.
/N number of days (always a number)
/D day-of-week number (used only with W function)
/A
/B For date functions, these two parameters are used to specify dates.
For the ordinary arithmetic functions, these parameters are used to
specify numbers. For date functions, if either of these parameters is
omitted, it defaults to today's date.
/T For date functions, /T overrides the time portion of the date on the
/A parm. (Note that it does NOT override the time portion of the date
on the /B parm.)
/I specifies format of input date(s)
If the /I parameter is omitted, /Imm-dd-ccyy is assumed.
/O specifies format of output date
If the /O parameter is omitted, /Od1 is assumed.
/L specifies language of output.
/Lus US (American) English-language output
/Lfr French-language output
/Lgr German-language output
/Lsp Spanish-language output
If the /L parameter is omitted, /Lus [American English] is assumed.
/V specifies that output is to be placed in an environment variable
rather than written to standard output.
If /V is specified but not followed by the name of an environment
variable, then /Vfdate is assumed, and output is placed in the FDATE
environment variable.
/P specifies a prefix string for the output
/S specifies a suffix string for the output
These optional parameters may always be specified or omitted.
They must be enclosed in single quotes, double quotes, or
square brackets
Note that "whitespace" will be removed from these strings,
so formatting of /P and /S strings cannot be controlled using
spaces. To format strings, use periods or ASCII 255 (hex'ff')
as filler.
EXAMPLES
FDATE /Ff /P"Today is "
FDATE /Fdif /B12-25-TTTT /P"It is " /S" days until Christmas"
OVERVIEW OF FUNCTIONS
=====================
Fdate's most important parameter, and the only one for which there is no
default value, is the function parameter, /F. Here is a brief summary of
the functions that may be specified on the /F parm, for example: /Fadd.
Detailed descriptions of each of the functions can be found on the next few
pages.
f Format the date in the /A parm into the format specified in the
/O parm
add Add the number of days in the /N parm to the date in the /A parm
sub Subtract the number of days in the /N parm from the date in the
/A parm
m Monthly arithmetic. Add the number of months in the /N parm to
the date in the /A parm. /N may be a negative number.
dif Return the number of days between dates in the /A and /B parms
w Do date arithmetic in terms of weeks rather than days. Using the
date in the /A parm, a number specified in the /N parm, and a
day-of-the-week number specified in the /D parm, return the date
of the /Nth /Day-of-the-week before (or after) /Adate.
e Echo the strings on the /P and /S parameters.
DATE/TIME COMPARISON FUNCTIONS
comp Compare the dates in the /A and /B parms. Return LT, EQ, or GT.
tcomp Compare the times specified on the /A and /B parms.
ORDINARY (AS OPPOSED TO DATE) ARITHMETIC FUNCTIONS
Functions whose names begin with "#" do ordinary arithmetic, i.e.
arithmetic on numbers rather than dates.
#add Add the integers specified on the /A and /B parms. To do
subtraction, add a negative number to a positive number.
#dif returns the difference between the integers specified on the /A
and /B parms.
#comp Compare the integers specified on the /A and /B parms. Return
LT, EQ, or GT.
#mod Modulus. Divide the integer on the /A parm by the integer on the
/B parm, and return the remainder.
#mult Multiply the integer on the /A parm by the integer on the /B
parm, and return the result.
#div Divide the integer on the /A parm by the integer on the /B parm,
and return the result as a decimal number with two decimal
places.
#idiv Integer division. Divide the integer on the /A parm by the
integer on the /B parm, and return the result as an integer.
FUNCTIONS: DETAILED DESCRIPTIONS
================================
DATE FORMATTING FUNCTIONS
=========================
FUNCTION FDATE /Ffunc /Adate /Iformat /Oformat
-------- -------------------------------------------
format this is a synonym for function "f"
f returns /Adate in format specified by /Oformat
Since /Aformat and /Oformat can be different, the FORMAT
function is used to change a date from one format to another.
Because of the wide variety of output formats, the FORMAT
function can also be used to determine the day of week of the
date, whether the date is in a normal or leap year, etc.
EXAMPLES
FDATE /Ff /A19920101 /Iccyymmdd /O"mn zd, ccyy"
FDATE /Ff /Atoday /Od1
FDATE /Fformat /Atoday /Od1
FDATE /Ff /If /Afdate.exe /P"FDATE.EXE last updated: " /Ofull
DATE ARITHMETIC FUNCTIONS
=========================
Internally, numbers in Fdate are stored in Turbo Pascal's LONGINT datatype,
which means that Fdate can accept numbers up to 9 digits long.
FUNCTION FDATE /Ffunc /Nnumdays /Adate /Iformat /Oformat
-------- -------------------------------------------
add Adds /Ndays to /Adate, produces date in /Oformat format
sub Subtracts /Ndays from /Adate, produces date in /Oformat format
EXAMPLES
FDATE /Fadd /N90 /A01-01-1992 /Imm-dd-ccyy /Od1
FDATE /Fsub /N90 /A01-01-1992 /Imm-dd-ccyy /Od1
FDATE /Fadd /N90 /Atoday /Od1
dif Returns number of days between /Adate and /Bdate
Order of the two dates is not significant.
NOTE THAT:
For DIF, both dates must be in the SAME format, the input format
specified in /Iformat. If the two dates are not in the same
format, you must first reformat one of the dates using the /Ff
function, then use DIF to get their difference.
EXAMPLES
FDATE /Fdif /A01-01-1992 /B11-11-1992 /Imm-dd-ccyy
FDATE /Fdif /A11-11-1992 /B01-01-1992 /Imm-dd-ccyy
FDATE /Fdif /Atoday /B01-01-1992 /Imm-dd-ccyy
MONTH DATE ARITHMETIC FUNCTIONS
===============================
FUNCTION FDATE /Ffunc /Nnumdays /Adate /Iformat /Oformat
-------- -------------------------------------------
m Adds /N months to /Adate, produces date in /Oformat format. This
function can also be used to do monthly subtraction by making the
number in the /N parameter a negative number.
EXAMPLES
FDATE /Fm /N1 /A03-15-1992 /Imm-dd-ccyy /Omm-dd-ccyy
produces: 04-15-1992
FDATE /Fm /N-1 /A03-30-1991 /Imm-dd-ccyy /Omm-dd-ccyy
produces: 02-28-1991
FDATE /Fm /N-1 /A03-30-1992 /Imm-dd-ccyy /Omm-dd-ccyy
produces: 02-29-1992
Note that a too-simple algorithm for month arithmetic can produce
non-existent dates. Subtracting a month from March 30, 1991 (as
in the second example) could produce a result of February 30,
1991, a date which cannot exist.
Fdate's month arithmetic is more sophisticated than that. If
Fdate finds that a simple month-arithmetic operation produces an
invalid date, it subtracts the minimum number of days required to
produce a valid date.
Thus, in the second example, it produces February 28, 1991, the
last date in February, 1991. In the third example, it produces
February 29, 1992 because 1992 is a leap year.
Note that telling Fdate to add 12 months to February 29, 1992 produces a
result of February 28, 1993, since 1993 is not a leap year. See Peter G.
Neumann's INSIDE RISKS column in COMMUNICATIONS OF THE ACM, June 1992 (Vol.
35, No. 6), entitled "Leap-Year Problems":
Prime Computer's MAGSAV failed at midnight [on Feb 29, 1992]... G. M.
Lack noted that MAGSAV probably failed on leap-day because it tried to
increment the year by one to set a tape label expiration date, and the
resulting nonexistent date of Feb 29, 1993 threw it for a loop.
WEEKDAY DATE ARITHMETIC FUNCTIONS
=================================
FUNCTION FDATE /Ffunc /Adate /Iformat /Oformat /Ddow# /Ndow-count
-------- -----------------------------------------------------------
w This function provides a way of doing date arithmetic in terms of
weeks rather than days.
This function accepts a date specification in parm /A and
returns the date of the /Nth /Day-of-the-week
before or after /Adate. For example:
If /A specifies November 14, 1992
/D specifies the number for Thursday (i.e., 5)
/N specifies a week count of 3
then /Fw returns the date of the third Thursday after
November 14, 1992. (See full example, below)
Note that /N may be negative. If, in the above example, /N
is specified as -3, then Fdate returns the date of the third
Thursday BEFORE November 14, 1992.
If the date specified on the /A parms falls on the same day
of the week as was specified on the /D parm, then that will
be considered to be the first date meeting that day-of-week
criterion. That is, if November 14, 1992 fell on a
Thursday, and if /N was 1 or -1, then the output date would
be the same as the input date, i.e. November 14, 1992.
The acceptable values for /N (number of weeks) is in
the range of 99..-99. A value of zero (i.e. /N0) is invalid.
EXAMPLES
find date of Thanksgiving (4th Thursday in November) in 1992
FDATE /Fw /A11-01-1992 /Imm-dd-ccyy /D5 /N4 /Od1
returns: Thursday November 26, 1992
find the beginning of the work-week (Monday, 2nd day of week)
AFTER Thanksgiving, 1992
FDATE /Fw /A11-26-1992 /Imm-dd-ccyy /D2 /N1 /Od1
find the beginning of the work-week (Monday, 2nd day of week)
BEFORE Thanksgiving, 1992
FDATE /Fw /A11-26-1992 /Imm-dd-ccyy /D2 /N-1 /Od1
get last Friday's date
rem Find next Friday's date (or today's date, if today is Friday).
rem Then find the Friday that precedes that Friday.
FDATE /Fw /At /Omm-dd-ccyy /D6 /N+1 /VGET
FDATE /Fw /A%GET% /Imm-dd-ccyy /D6 /N-2 /VGET
Echo Last Friday was %GET%
DATE/TIME COMPARISON FUNCTIONS
==============================
FUNCTION FDATE /Ffunc /Adate /Bdate /Iformat
-------- -------------------------------------------
comp compares the dates (time granularity = 1 day)
specified on the /A and /B parms.
returns when
LT /A is less than (earlier than) /B
EQ /A is equal to (same as) /B
GT /A is greater than (later than) /B
tcomp compares the times (time granularity = 1 second)
specified on the /A and /B parms.
This is useful when input format /If (file) is specified.
It can be used to compare the timestamps of two files and
determine which is older.
EXAMPLE: Fdate /Ftcomp /If /Amyfile.1 /Byourfile.1
returns when
LT /A is less than (earlier than) /B
EQ /A is equal to (same as) /B
GT /A is greater than (later than) /B
NUMERIC ARITHMETIC FUNCTIONS
============================
Note that all of Fdate's arithmetic functions operate on integers. A
decimal number on an input parameter will be rejected, and an error message
will be displayed.
FUNCTION FDATE /Ffunc /Anum /Bnum
-------- -------------------------------------------
#add returns the sum of the integers specified
on the /A and /B parms. Can be used to calculate the
"absolute" minute(second, date) in the future from a given
"absolute" minute(second, date). Also useful in generating
sequences of numbers and looping (see EXAMPLES).
#sub (not supported)
Fdate does not provide a numeric subtraction operation as such.
To do subtraction, add two numbers, one of which is a negative
number. For example, to subtract 3 from 2:
FDATE /F#add /A2 /B-3 [ returns: -1 ]
#dif returns the difference between the integers specified on the /A
and /B parms. #dif is the same as subtraction in which the
smaller number is subtracted from the larger number; it will
never return a negative number. It can be used to calculate the
number of minutes(seconds, days) between two
"Absolute" minutes(seconds, dates).
#comp compares the integers specified on the /A and /B parms.
returns when
LT /A is less than /B
EQ /A is equal to /B
GT /A is greater than /B
#mod divides the integer on the /A parm by the integer on the /B parm,
and returns the remainder.
This is useful for determining whether a number is evenly
divisible by some other number. If the remainder is 0, then /A
is evenly divisible by /B. If a year is evenly divisible by 4,
for example, then it is an American election year. If it is
evenly divisible by 100, then it is a century year, etc.
#mult multiplies the integer on the /A parm by the integer on the /B
parm, and returns the result.
#div (division) divides the integer on the /A parm by the integer on
the /B parm, and returns the result as a decimal number, with two
digits to the right of the decimal.
This is useful for dividing a number (representing the number of
minutes in some period) by 60 to get the length of the period
expressed in terms of hours, or by 1440 to get the length of the
period expressed in terms of days. Or you could divide a number
of days by 7 to get the number of weeks, etc.
#idiv (integer division) divides the integer on the /A parm by the
integer on the /B parm, and returns the result as an integer.
This is useful, especially in conjunction with the #mod function,
for converting a number of minutes into a number of hours and
minutes, or days and hours and minutes. See the EXAMPLES
section, below.
DATE VALIDATION FUNCTION
========================
v If the date specified on the /A parm is valid, produces "" (the null
string). Otherwise, produces "ERROR" and a non-zero errorlevel by
triggering Fdate's error-handling function. (See the section on
FDATE'S ERROR HANDLING, later in this documentation.)
When processing an input date, Fdate does not reject all invalid
dates: specifically, it is very forgiving about the number in the day-
of-the-month part of input dates. It will accept, for example,
19931144 (November 44, 1993 in CCYYMMDD format) and process it quite
happily (as December 14, 1993). This is not a bug, it is a feature.
This feature provides one way (admittedly a crude one) of doing date
arithmetic. The date part (JJJ) of a Business Julian input date can
be used in the same way.
This feature can be a drawback, however, if you want to be sure that
some date (say a date that a user entered as an input parameter) is
valid. The /Fv function provides a way of completely checking a date
for validity. It will, for example, reject November 44, 1993 as
invalid.
ECHO FUNCTION
=============
e Produces only the strings specified using the /P and /S
parameters.
You can use /Fe for situations in which you want Fdate to produce output
that doesn't include any sort of date. In these cases, Fdate functions
just like the DOS "echo" command.
The real use for /Fe is in conjunction with /V, where it can be used to
manipulate the environment in ways that DOS's SET command cannot:
(1) to give a value to an environment variable that it would not accept
from the SET command (e.g. a value that contained "=").
(2) to redirect or pipe a character-string that contains a redirection
symbol ">" or pipe symbol "|".
This feature is for real batch-file power users.
EXAMPLE BATCH FILE
------------------
@ECHO OFF
set pct=%%%
Fdate /Fe /P"=Sam=" /vName
Fdate /Fe /P"echo ECHO Hi, %pct%Name%pct%!>junk2.bat">junk1.bat
: RESULT: TEXT OF JUNK1.BAT IS
: echo ECHO Hi, %Name%!>junk2.bat
call junk1.bat
: RESULT: TEXT OF JUNK2.BAT IS
: ECHO Hi, =Sam=!
call junk2.bat
: RESULT: TEXT DISPLAYED ON SCREEN IS
: Hi, =Sam=!
:endit
DATE FORMATS
============
SYMBOL CONVENTIONS
==================
The following symbols are used in specifying date formats:
SYMBOL EXAMPLE MEANING
------ ------- -------------------------------------
cc 19 century
yy 93 year
mm 02 month
zm 2 month without leading zero
dd 08 day
zd 8 day without leading zero
mn February month name
mn3 Feb month name, first 3 characters only
dow Tuesday day of week
dow3 Tue day of week, first 3 characters only
dow# 3 day of week as a number (Sunday=1, Monday = 2, etc.)
today is a "pseudodate" representing the current date
t is an alias for the "today" pseudodate
hh:mm 09:05 hours and minutes
hhmm 0905 hours and minutes
ss 13 seconds
PSEUDODATES
===========
t (or today)
can be used with either /A or /B, e.g. /Atoday or /At.
This is the default for both /A and /B. That is, if /A is not
specified, /At is assumed, and the same for /B.
NOTE THAT
"Today" as a date specification operates independently of any
input format. You need to specify an input format (either
explicitly via the /I parameter, or implicitly by accepting the
default value of /I) only for input dates that are supplied to
Fdate in some other way than via the "today" pseudodate: as a
date literal, a filename, etc.
EXAMPLES:
rem Get the date that is 90 days from today
FDATE /Fadd /N90 /Atoday /Omm-dd-ccyy
FDATE /Fadd /N90 /At /Omm-dd-ccyy
rem determine if this year is a leapyear
FDATE /Ff /At /OLY
tttt When used in place of a 4-digit CCYY string, "tttt"
will cause Fdate to use today's 4-digit year (CCYY).
tt When used in place of a 2-digit DD, MM, or YY string,
"tt" will cause Fdate to use today's day-of-the-month,
month, or 2-digit year, respectively.
Note that "tt" can NOT be used for the YY portion of a CCYY
input year. The following, for example, is NOT valid:
FDATE /Ff /Imm-dd-ccyy /A01-01-19tt /Od1
EXAMPLES:
FDATE /Ff /Imm-dd-ccyy /A01-01-tttt
FDATE /Ff /Imm-dd-yy /A01-01-tt
rem report the 15th day of this month, this year
FDATE /Ff /Imm-dd-ccyy /Att-15-tttt
rem Show the first Monday in the second quarter of this year
FDATE /Fw /Iccyymmdd /Atttt0401 /D2 /N1 /P"First Monday in QTR#2: "
rem Show the last Friday on/before the 15th of this month.
FDATE /Fw /Iccyymmdd /Atttttt15 /D6 /N-1 /P"Friday before the 15th: "
INPUT DATE FORMATS
==================
CALENDAR DATE INPUT FORMATS
===========================
FORMAT EXAMPLES DISCUSSION
------ --------- -----------------------------
ccyymmdd 19922002
On the /I (input format) parm, the separator character of the following
input formats must be a dash. This simply tells Fdate that the input
date will contain SOME separator character. The separator character that
actually occurs in dates in the /A and /B parms is ignored, and may be
any non-numeric character: a slash "/", a dash "-", a dot ".", etc.
In specifications that begin with "mm-dd" or "dd-mm", leading zeros need
not be present in the "mm" and "dd" part of the date.
ccyy-mm-dd 1992-02-20 Leading zeros MUST be present, since the
1992/02/20 date does not begin with dd-mm or mm-dd.
1992.02.20
mm-dd-ccyy 02-20-1992
02/20/1992 The dash represents ANY non-numeric character.
2-5-1992 Leading zeros need not be present.
2/5/1992
mm-dd-yy 02-05-92 February 5, 1992. See discussion of
2/5/92 FDATE'S CENTURY ASSUMPTION ALGORITHM, below
---------------------------------------
In the following formats, days
precede months (European style)
---------------------------------------
dd-mm-ccyy 05-02-1992
05/02/1992
5-2-1992 Leading zeros need not be present.
5/2/1992
dd-mm-yy 05-02-92 February 5, 1992. See discussion of
5/2/92 FDATE'S CENTURY ASSUMPTION ALGORITHM, below
BUSINESS JULIAN DATE INPUT FORMATS
==================================
These are formats for "business julian" dates: dates expressed as the
number of days from the beginning of the year, when January 1 is day 1.
EXAMPLES:
date BUSINESS JULIAN DATE
----------- --------------------
Jan 5, 1992 92005
Jan 5, 1993 93005
Dec 31, 1993 93365 [Dec 31 is 365th day of year 1993]
Dec 31, 1996 96366 [Dec 31 is 366th day, because 1996 is a leap year]
-----------------------------------------------------------------------
NOTE: * JJJ can be 1 - 4 digits
* may include a prefix of a plus or minus ( + or - ) sign
-----------------------------------------------------------------------
FORMAT EXAMPLES DISCUSSION
------ --------- -----------------------------
ccyyjjj 1992003 Third day of 1992, i.e. Jan 3, 1992
19923 Third day of 1992
tttt003 Third day of this year
tttt3 Third day of this year
yyjjj 92003 Third day of 1992
923 Third day of 1992
tt003 Third day of this year
tt3 Third day of this year
01003 Third day of 2001 See
FDATE'S CENTURY ASSUMPTION ALGORITHM, below
NOTE THAT FDATE WILL ACCEPT "JJJ" OF LESS THAN 1 & MORE THAN 366.
-----------------------------------------------------------------
yyjjj tt1000 the 1000th day from beginning of this year
tt0 last day of last year
tt-1 next-to-last day of last year
FDATE /Ff /Iccyyjjj /Od1 /A1992-1 produces... Monday December 30, 1991
FDATE /Ff /Iccyyjjj /Od1 /A19920 produces... Tuesday December 31, 1991
FDATE /Ff /Iccyyjjj /Od1 /A1992+1 produces... Wednesday January 1, 1992
FDATE /Ff /Iccyyjjj /Od1 /A1992366 produces... Thursday December 31, 1992
FDATE /Ff /Iccyyjjj /Od1 /A1992367 produces... Friday January 1, 1993
This feature allows limited date arithmetic with ordinary business
Julian days. For example, 90 days from tt300 can be shown by:
FDATE /Ff /Iyyjjj /Att390
GETTING DATE/TIME A FILE WAS CREATED
====================================
FORMAT EXAMPLES DISCUSSION
------ --------- -----------------------------
f MYFILE.1 Input format F (file) tells Fdate that
/A and /B will specify filenames, and that
Fdate should pick up the input date and time
from the date/time stamp on a file.
Note that if you specify /If, then both /A and /B will be interpreted
as filenames.
It is not possible to put a filename in /A and a date literal in /B,
and then use the "comp" or "dif" function to compare them. You must
first extract the file's date into an environment variable, and then
compare that environment variable to the date literal.
The only exception to this rule is the pseudodate "t" (i.e. /At
or /Bt) which will pick up the current date and time from the
system clock. This feature will allow you, for example, to
compare the date of a file to today's date (see EXAMPLES).
A filename may (but need not) be fully qualified: i.e. "MYFILE.1" and
"C:\DBASE\WORKDIR\MYFILE.1" are both acceptable.
A filename may contain wildcards. If it does, the date/time stamp
will be retrieved from the first file that FDATE finds that meets the
filespec. Giving FDATE a filespec containing a wildcard is pretty
useless, but FDATE will not reject it.
OUTPUT DATE FORMATS
===================
FORMAT EXAMPLES DISCUSSION
------ --------- -----------------------------
dd-mn3-yy 08-Feb-92 CompuServe-style date
yy 93 2-digit year number
ccyy 1993 4-digit year number (includes century)
ccyymm 199302 useful for triggering monthly processing
ccyymmdd 19930208 useful for putting current date in filename
yymmdd 908208 useful for putting current date in filename
mmdd 0208
mm 02 2-digit month number
zm 2 month number, no leading zeros
dd 08 2-digit day-of-month number
zd 8 day-of-month number, no leading zeros
In the following formats, months precede days (American style)
------------------------------------------------------------------
mm/dd/ccyy 02/08/1993
mm-dd-ccyy 02-08-1993
mm.dd.ccyy 02.08.1993 British-style dates
zm/zd/ccyy 2/8/1993 no leading zeros in day or month
zm-zd-ccyy 2-8-1993 no leading zeros in day or month
zm.zd.ccyy 2.8.1993 British-style dates
mm/dd/yy 02/08/92
mm-dd-yy 02-08-92
mm.dd.yy 02.08.92 British-style dates
zm/zd/yy 2/8/92 no leading zeros in day or month
zm-zd-yy 2-8-92 no leading zeros in day or month
zm.zd.yy 2.8.92 no leading zeros in day or month
In the following formats, days precede months (European style)
------------------------------------------------------------------
dd/mm/ccyy 02/08/1993
dd-mm-ccyy 02-08-1993
dd.mm.ccyy 02.08.1993 British-style dates
zd/zm/ccyy 2/8/1993 no leading zeros in day or month
zd-zm-ccyy 2-8-1993 no leading zeros in day or month
zd.zm.ccyy 2.8.1993 British-style dates
dd/mm/yy 02/08/92
dd-mm-yy 02-08-92
dd.mm.yy 02.08.92 British-style dates
zd/zm/yy 2/8/92 no leading zeros in day or month
zd-zm-yy 2-8-92 no leading zeros in day or month
zd.zm.yy 2.8.92 British-style dates
DAY-OF-WEEK AND MONTH OUTPUT FORMATS
====================================
dow# 5 Sunday=1, Monday=2 .... Saturday=7.
dow Thursday name of day of week
jeudi if /Lfr specified
Donnerstag if /Lgr specified
dow3 Thu first 3 characters of name of day of week
jeu if /Lfr specified
Don if /Lgr specified
mn February name of month
fevrier if /Lfr specified
Februar if /Lgr specified
mn3 Feb first 3 characters of name of month
fev if /Lfr specified
Feb if /Lgr specified
MISCELLANEOUS OUTPUT FORMATS
============================
full 9:05 pm on Wednesday February 5, 1992
9:05 pm, mercredi le 5 fevrier 1992 [/Lfr specified]
9:05 pm, miércoles el 5 de febrero de 1992 [/Lsp specified]
Mittwoch, 5. Februar 1992, 21:05 [/Lgr specified]
d1 Saturday, February 5, 1992
samedi le 5 fevrier 1992 [/Lfr specified]
Mittwoch, 5. Februar 1992 [/Lgr specified]
ddmn3yy 05Feb92
-----------------------------------------------------------------------
NOTE that the following formats contain embedded spaces. Consequently
they must be enclosed in double quotes. EXAMPLE: /O"mn zd, ccyy".
-----------------------------------------------------------------------
"zd mn ccyy" 5 February 1992
"zd mn, ccyy" 5 February, 1992
"zd. mn ccyy" 5. February 1992 [German-style date format]
"zd. mn3 ccyy" 5. Feb 1992 [German-style date format]
"mn3 dd ccyy" Feb 05 1992
"mn3 dd, ccyy" Feb 05, 1992
"mn zd, ccyy" February 5, 1992
LEAP-YEAR FLAG OUTPUT FORMAT
============================
LY 0 "1" if date occurs in a leapyear, otherwise "0".
365 + this number gives total number of days in the year.
28 + this number gives total number of days in February.
TIME OUTPUT FORMATS
===================
See also: the section on the /T (parm /A time override) parameter.
t1 9:05 am
9:05 pm
HH:MM 09:05 24-hour time, hours:minutes
21:05
HHMM 0905
2105
HH:MM:SS 21:05:30 24-hour time, hours:minutes:seconds
HHMMSS 210530
BUSINESS JULIAN DATE OUTPUT FORMATS
===================================
These are formats for "business julian" dates: dates expressed as the
number of days from the beginning of the year, when January 1 is day 1.
EXAMPLES:
DATE BUSINESS JULIAN DATE
----------- --------------------
Jan 5, 1993 93005
Dec 31, 1993 93365 [Dec 31 is 365th day of year 1993]
Dec 31, 1996 96366 [Dec 31 is 366th day, because 1996 is a leap year]
FORMAT EXAMPLES DISCUSSION
------ --------- -----------------------------
ccyyjjj 1992027 Jan 27, 1992
yyjjj 92027 "Business Julian" date expressed as number
jjj 027 of days since January 1 of the same year.
zzj 27 Note leading zero suppression in "zzj".
ABSOLUTE DATE/TIME OUTPUT FORMATS
=================================
See also: the section on the /T (parm /A time override) parameter.
day# 727198 "Absolute date": date expressed as number
of days since January 1, 0001.
minute# 33088 "Absolute minutes": time expressed as number
of minutes since midnight, January 1, 1990.
second# 633088 "Absolute seconds": time expressed as number
of seconds since midnight, January 1, 1990.
Running FDATE with /O parameter for an "absolute time" produces a
number based on the current time of day and the date in the /A parm.
If, on January 10, 1992 at 2 pm, you run FDATE this way:
FDATE /Ff /Atoday /Ominute#
it will produce the absolute minute for January 10, 1992 at 2 pm.
If, on January 10, 1992 at 2 pm, you run FDATE this way:
FDATE /Ff /A01-15-1992 /Imm-dd-ccyy /Ominute#
it will produce the absolute minute for January 15, 1992 at 2 pm.
/T: TIME OVERRIDE PARAMETER
===============================
You may override Fdate's use of the current time -- for the /A parameter
only -- by using the /T parameter. The /T parameter specifies a time of
day in the 24-hour format hh:mm:ss (hours:minutes:seconds). Leading zeros
in each of the three fields (hh, mm, ss) may be omitted. The seconds field
may be omitted; if omitted, it defaults to "00".
Note that the /T parm overrides the time portion of the /A date, but it
does NOT override the time portion of the /B date.
If, on January 10, 1992 at 2 pm, you run FDATE this way:
FDATE /Ff /A01-15-1992 /Imm-dd-ccyy /Ominute# /T5:12
it will produce the absolute minute for January 15, 1992 at 5:12 am.
The most frequent and important use of the /T parm is with the format
function (/Ff) to obtain the "absolute" minute of a specific date and time.
Once we have the absolute minutes of two different date/times, we can
easily obtain the time between them (expressed in days, hours, and minutes)
by using Fdate's #dif, #idiv, and #mod functions. (In the EXAMPLES
section, see the example that contains FORATIME.BAT.)
It is also possible to use /T in conjunction with the time compare function
(/Ftcomp).
@echo ON
cls
rem Since both /A and /B default to the current date and time,
rem and since /T parm overrides the time only for the /A parm ...
rem ... during daytime hours, this will always return LT
Fdate /ftcomp /T00:00:00
rem ... during daytime hours, this will always return GT
Fdate /ftcomp /T23:59:59
HOW TO PUT FDATE OUTPUT INTO AN ENVIRONMENT VARIABLE
====================================================
CALL A BATCH FILE
=================
The most basic way to put FDATE's output into an environment variable is
to:
* use the /P (prefix string) feature to create a DOS "SET" statement,
* redirect the output to a batch file, and then
* CALL the batch file.
Since CALL first appeared in DOS 3.3, you will need DOS 3.3 or greater
to use this technique.
FDATE /Ff /Atoday /O"mn zd, ccyy" /P"@SET FDATE=" >JUNKTEMP.BAT
call JUNKTEMP.BAT
del JUNKTEMP.BAT
USE AN ENVIRONMENT-MANIPULATION UTILITY
=======================================
There are shareware and public domain utilities that are written
specifically to manipulate environment variables, and do that job very
well. FDATE's output can be put into an environment variable by piping
it to one of these utilities. When piping FDATE output to a utility,
you can prevent the output from being ECHOed to the screen by
redirecting the output to NUL.
Of these utilities, I can especially recommend Bob Stephan's GET
(because it is very powerful and flexible) and PC Magazine's STRINGS
(because it is free to ZiffNet members). See the EXAMPLES section for
examples of how to use STRINGS and GET to put FDATE's output into an
environment variable.
As of February 14, 1992, the current version of GET is 2.5. On
CompuServe, use IBMFF to look for GET*.ZIP (e.g. GET25.ZIP for version
2.5) in CIS:IBMSYS, or for GET.ZIP in ZNT:UTILFORUM, lib 16. GET is
also available from the Public Software Library in Houston.
As of February 14, 1992, the current version of STRINGS is 1.3. On
CompuServe, look for STRING.ZIP in the PC Magazine Utilities Lib of
ZNT:UTILFORUM. STRHYP.ZIP contains good hypertext documentation on
STRINGS.
FDATE'S /V PARAMETER
====================
Manipulating the environment is an incredibly tricky business. There
are questions of the local versus master environment, the version of DOS
you are running, and the environment under which you are running (DOS,
Windows, Carousel). In order to keep FDATE focussed on date-related
issues, versions of Fdate prior to 6.1 did not attempt to put output
directly into an environment variable. Instead, FDATE's output was
written to standard output, that is, it was displayed on the screen.
Output could then be redirected to a batch file, or piped to a utility
(such as STRINGS or GET), that would put the output into an environment
variable.
Starting with version 6.1, Fdate supports a /V (environment variable)
parameter. A user can use /V to tell Fdate to put its output directly
into an environment variable. (Fdate attempts to put output into an
environment variable in the master, rather than the local, environment.)
NOTE that due to the complexities of manipulating the environment, there
may be circumstances where /V doesn't work. These include running FDATE
when you have shelled out to DOS from another program, have put the
command processor in upper memory (UMB) (see below), are running under
Windows, Carousel, etc. In such cases, you may be able to use one of
the more basic techniques described above. For a list of environments
in which the /V option has been reported as NOT working, see the next
section.
/Vevar tells Fdate to put output into an environmental variable whose
name is "evar". For example:
Fdate /Ff /Vdate1
will set the environment variable DATE1 to the current date. If you
type SET at the DOS prompt, you should see something like:
DATE1=Friday February 14, 1992
If you specify /V without an evar name, the evar name defaults to FDATE.
Example : Fdate /Ff /V
produces: FDATE=Friday February 14, 1992
If you do not use /V, Fdate output is written to standard output, i.e.
to the screen.
/V WHEN USING 4DOS, NDOS, AND UMB
=================================
--------------------------------------------------------------
I have received the following report from Aran Spence about
circumstances in which FDATE /V will not set a variable
in the master environment. This report leads me to believe
that FDATE /V may also fail to work with MS-DOS if you put
the command processor or the environment in Upper Memory.
--------------------------------------------------------------
Steve,
There are options with 4DOS and NDOS to load the environment and part
of the command processor into upper memory blocks. When one of these
options is used, FDATE /V can't find the environment and produces the
message:
ERROR
echo ERROR: Master environment not found
pause
If you have a 4DOS.INI file, it has to contain these lines for FDATE /V
to work:
UMBEnvironment = No
UMBLoad = No
If you have NDOS, the SHELL statement in CONFIG.SYS cannot contain
any reference to UMB loading via /U (which puts NDOS.COM in UMB), nor
can it contain a statement of the form:
/E:xxxU
(which puts xxx bytes of the environment in UMB via the "U" parameter).
Also, NSTART.BTM or 4START.BTM cannot contain
SET NDSHELL=/e+xxxU /U
in which both U's represent UMB loading of the command processor and the
environment during secondary shells.
FDATE'S ERROR HANDLING
======================
If FDATE detects an error:
(1) it will return an errorlevel of 1 (rather than 0), and
(2) its output will be 3 lines:
* the word ERROR
* a DOS batch-file ECHO statement that displays an error message
* a DOS batch-file PAUSE statement
If Fdate output is displayed directly, or redirected to NUL,
you can detect an error by testing the errorlevel for a value of 1.
If Fdate output is piped to an environment manipulation utility such
as STRINGS or GET, the environment variable will be set to ERROR.
Errorlevel will be set by STRINGS/GET, and will probably be 0.
In such a case, the only way to detect an error is to test the
environment variable for the value ERROR.
If FDATE output is redirected to a batch file, which is then
CALLed to set an environment variable, the batch file will:
* set the environment variable to ERROR,
* ECHO the error message, and
* pause.
You can detect an error by testing errorlevel for the value 1
either before or after you CALL the batch file, or
by testing the environment variable for the
value ERROR, AFTER you have CALLed the batch file.
----------------------------------------------------------------------
EXAMPLE:
rem use FDATE to check validity of year in parm %1
Fdate /Fv /Imm-dd-ccyy /ATT-TT-%1 > nul
if errorlevel 1 echo Year parm [%1] is not valid.
if errorlevel 1 goto endit
EXAMPLE:
rem use FDATE to validate %1, and GET to put it into %year%
Fdate /Ff /Imm-dd-ccyy /ATT-TT-%1 /Occyy | GET ZE /V%year% >nul
if (%year%)==(ERROR) echo Year parm [%1] is not valid.
if (%year%)==(ERROR) goto endit
EXAMPLE:
rem use FDATE to validate %1, call a batch file to put it into %year%
Fdate /Ff /Imm-dd-ccyy /ATT-TT-%1 /Occyy /P"@set year=">junktemp.bat
call junktemp.bat
del junktemp.bat
if errorlevel 1 echo Year parm [%1] is not valid.
if errorlevel 1 goto endit
EXAMPLES OF HOW TO USE FDATE
============================
:01 Display Fdate output on screen
:==================================================================
FDATE /Ff /At /Od1 /P"Today is "
:02 Redirect FDATE output to a file
:==================================================================
FDATE /Ff /At /Od1 /P"Today is " >FDATE.OUT
:03 Put FDATE output in an environment variable using a batch file
:==================================================================
FDATE /Ff /Atoday /O"mn zd, ccyy" /P"@SET DATE1=" >JUNKTEMP.BAT
call JUNKTEMP.BAT
del JUNKTEMP.BAT
:04 Put FDATE output in an environment variable using /V parm
:==================================================================
FDATE /Ff /Atoday /O"mn zd, ccyy" /Vdate1
:05 Put FDATE output in an environment variable using STRINGS
:==================================================================
FDATE /Ff /Atoday /O"mn zd, ccyy" |STRINGS date1= ASK >NUL
:06 Put FDATE output in an environment variable using GET
:==================================================================
FDATE /Ff /Atoday /O"mn zd, ccyy" |GET ZE /Vdate1 >NUL
:07 Change a date from one format into another
:==================================================================
FDATE /Ff /Imm-dd-yy /A05-08-92 /Occyymmdd
:11 Find the difference in days between two dates
:==================================================================
FDATE /Fdif /Imm-dd-ccyy /A%date1% /B%date2% /vdiff
echo The difference is %diff% days.
:12 Find the elapsed days/hours/minutes between two date/times.
:===================================================================
This batch file was developed in cooperation with Walter Ledge, a sysop for
CompuServe's CRFORUM. In addition to being a good example of how to use
Fdate's /T parm and "#idiv" function, it should be useful for other
CompuServe sysops who need to submit the same reports that Walt does.
Here's Walt's message that started the whole thing.
As an assistant sysop on the CRFORUM, I have to submit reports to CIS on
the number of messages that are posted on our forum in terms of time per
1,000 messages -- i.e., say, I know that 1,000 messages were posted
between the hours of 17:05 on July 5 and 3:03 on July 7. I need to know
how many hours and minutes it took for those 1000 messages to be posted.
So I would like some way to use FDATE to calculate the difference
between those two times (which, of course, include the dates).
@echo off
cls
rem ------------------------------------------------------
rem FORATIME.BAT batch file parms
rem Dates must include full 4-digit for year: mm-dd-ccyy
rem Times must be in 24-hour format: hh:mm
rem ------------------------------------------------------
set BEGdate=%1
set BEGtime=%2
set ENDdate=%3
set ENDtime=%4
ECHO Validating input parms ...
fdate /fv /A%BEGdate% /T%BEGtime%
if errorlevel 1 goto endit
fdate /fv /A%ENDdate% /T%ENDtime%
if errorlevel 1 goto endit
rem get absolute minute of start date/time
fdate /ff /ominute# /A%BEGdate% /T%BEGtime% /VABStime1
fdate /ff /ofull /A%BEGdate% /T%BEGtime% /Vfull1
rem get absolute minute of end date/time
fdate /ff /ominute# /A%ENDdate% /T%ENDtime% /VABStime2
fdate /ff /ofull /A%ENDdate% /T%ENDtime% /Vfull2
rem calculate the difference between ABStime1 and ABStime2
fdate /f#dif /A%ABStime1% /B%ABStime2% /VMinutes
:
rem calculate the number of hours in it took
fdate /f#Idiv /A%minutes% /B60 /VHours
rem calculate the number of extra minutes it took
fdate /f#mod /A%minutes% /B60 /VMins
echo Begin date time: %BEGdate% %BEGtime%
echo End date time: %ENDdate% %ENDtime%
echo.
echo It took %hours% hours and %mins% minutes
echo between %full1%
echo and %full2%
echo.
fdate /f#Idiv /A%minutes% /B1440 /Vday1
fdate /f#mod /A%minutes% /B1440 /Vmin1
fdate /f#Idiv /A%min1% /B60 /Vhour1
fdate /f#mod /A%min1% /B60 /Vmin2
echo or, expressed another way ...
echo a total of: %day1% day(s) %hour1% hour(s) and %min2% minute(s).
echo.
echo.
REM cleanup
set ENDdate=
set BEGdate=
set BEGtime=
set ENDtime=
set full1=
set full2=
set minutes=
set ABStime1=
set ABStime2=
set day1=
set hour1=
set min1=
set min2=
set mins=
set hours=
:endit
:13 Time the execution of a piece of software
:==================================================================
COMMENT
This example was developed coded before the addition of the #div and
#idiv functions to Fdate, so the run time (in minutes) is not calculated
by dividing the run time (in seconds) by 60, as it now could be.
@echo off
cls
ECHO The demo will run for 1 - 60 seconds.
echo.
ECHO ─────────────────────────────────────────────────────────────────────
ECHO CALCULATE HOW LONG IT TOOK TO RUN A PROGRAM (in seconds and minutes)
echo.
echo If you leave long batch files to run overnight, this technique can
echo be used to record how long each program in the batch file ran.
echo.
echo The technique for setting the values of environment variables in this
echo part of the demo uses temporary batch files and CALL statements.
echo If you have a program such as GET or STRINGS, you can use it instead.
ECHO ──────────────────────────────────────────────────────────────────────
echo.
PAUSE
cls
FDATE /Ff /At /Ohh:mm:ss /P"TESTPGM simulated execution begins at "
REM GET PROGRAM BEGIN TIME, IN MINUTES
@set BegM=
@set EndM=
@set RunM=
FDATE /Ff /At /Ominute# /P"SET BegM=" >FDATJUNK.BAT
CALL FDATJUNK.BAT
REM GET PROGRAM BEGIN TIME, IN SECONDS
set BegS=
set EndS=
set RunS=
FDATE /Ff /At /Osecond# /P"SET BegS=" >FDATJUNK.BAT
CALL FDATJUNK.BAT
rem ───────────────────────────────────────────────────────────────
rem [simulate execution of a program: loop for a minute or less]
rem [In a real batch file, you would put your program statements here]
rem ───────────────────────────────────────────────────────────────
:BegLoop
FDATE /Ff /At /Osecond# /P"SET EndS=" >FDATJUNK.BAT
CALL FDATJUNK.BAT
FDATE /Ff /At /Ominute# /P"SET EndM=" >FDATJUNK.BAT
CALL FDATJUNK.BAT
rem calculate run time (difference between start time and end time)
FDATE /F#dif /A%EndM% /B%BegM% /P"SET RunM=" > FDATJUNK.BAT
CALL FDATJUNK.BAT
rem calculate run time (difference between start time and end time)
FDATE /F#dif /A%EndS% /B%BegS% /P"SET RunS=" > FDATJUNK.BAT
CALL FDATJUNK.BAT
echo TESTPGM running, elapsed time: %RunS% seconds
if (%RunM%)==() goto EndLoop
if (%RunM%)==(0) goto BegLoop
:EndLoop
rem ───────────────────────────────────────────────────────────────
REM GET PROGRAM END TIME IN SECONDS
FDATE /Ff /At /Osecond# /P"SET EndS=" > FDATJUNK.BAT
CALL FDATJUNK.BAT
REM GET PROGRAM END TIME IN MINUTES
FDATE /Ff /At /Ominute# /P"SET EndM=" > FDATJUNK.BAT
CALL FDATJUNK.BAT
FDATE /Ff /At /Ohh:mm:ss /P"TESTPGM simulated execution ends at "
echo.
echo TESTPGM: Program end time (Absolute seconds): %EndS%
echo TESTPGM: Program begin time (Absolute seconds): %BegS%
rem calculate run time (difference between start time and end time)
FDATE /F#dif /A%EndS% /B%BegS% /P"TESTPGM: Run time in seconds= "
set BegS=
set EndS=
echo.
echo TESTPGM: Program end time (Absolute minutes): %EndM%
echo TESTPGM: Program begin time (Absolute minutes): %BegM%
rem calculate run time (difference between start time and end time)
FDATE /F#dif /A%EndM% /B%BegM% /P"TESTPGM: Run time in minutes= "
DEL FDATJUNK.BAT
set BegM=
set EndM=
set RunM=
set RunS=
:15 Find calendar date corresponding to a "business Julian" date
:==================================================================
rem business julian date is 1992:045. Note input format CCYYjjj
FDATE /Ff /A1992045 /Iccyyjjj /Od1
rem You don't need to left-zero-fill the day
FDATE /Ff /A199245 /Iccyyjjj /Od1
rem You can assume the century, if you specify the YYjjj input format
FDATE /Ff /A9245 /Iyyjjj /Od1
:16 Set your PC's date to a business julian date
:==================================================================
@echo off
goto enddoc
---------------------------------------------------------------------
JDATE.BAT
This batch file was created by Aran Spence [CIS: 70162,3044]. Its function
is to emulate the DOS DATE command, but to allow the user to set the date
using a business julian date format (yyjjj) instead of mm-dd-yy.
Note the format is YYjjj. This is the BUSINESS julian date: a date
expressed as the number of days from the beginning of the year, when
January 1 is day 1.
date BUSINESS julian date
----------- --------------------
Jan 5, 1992 92005
Jan 5, 1993 93005
Dec 31, 1993 93365 [Dec 31 is 365th day of year 1993]
As Aran originally wrote it, the user-prompt was virtually identical to
that of the DATE command. I have modified his original version, so it
now looks less like the DATE command but displays a bit more
information, and so it can operate from the command line even if the
user does not have GET.
If the user enters a business julian date as a command-line
parameter, JDATE resets the date to that julian date.
EXAMPLE: JDATE 92005
If there is no input parameter, GET is used to prompt the user for a
date. It is possible to use JDATE even if you don't have GET by
operating only from the command line, or by substituting some other
utility (such as STRINGS) for GET.
Note that the user must enter both of the year digits (yy),
but may enter an abbreviated set of day digits (jjj). That is,
for julian day 92005, the user is permitted to enter 925.
One handy use for JDATE is simply to find out what the current
business julian date is.
---------------------------------------------------------------------
:enddoc
SET NewJD=%1
if not (%NewJD%)==() goto GotDate
:ShowDate
Fdate /Ff /Od1 /P"Current Gregorian date: "
Fdate /Ff /Oyyjjj /P"'Business Julian' date: "
:GetDate
GET S "Enter new date (yyddd): " /VNewJD /L
if (%NewJD%)==() goto endit
:GotDate
Fdate /Ff /A%NewJD% /Omm-dd-yy /Iyyjjj /P"@DATE " > JUNKTEMP.BAT
if errorlevel 1 if exist JUNKTEMP.BAT del JUNKTEMP.BAT
if errorlevel 1 echo Invalid date "%NewJD%"
if errorlevel 1 goto GetDate
rem reset the date by calling JUNKTEMP.BAT
call JUNKTEMP.BAT
del JUNKTEMP.BAT
echo SYSTEM DATE HAS BEEN RESET
Fdate /Ff /Od1 /P"Current Gregorian date: "
Fdate /Ff /Oyyjjj /P"'Business Julian' date: "
:endit
SET NewJD=
echo.
:18 Determine if parm %1 contains a valid date
:==================================================================
COMMENT
Note that we throw away the FDATE output by redirecting it to NUL. All
we really want here is the errorlevel, which tells us whether or not the
string in %1 is a valid year.
Fdate /Fv /Imm-dd-ccyy /A%1 >nul
if errorlevel 1 echo Parm 1 was not a valid date: %1
if errorlevel 1 goto endit
:
: Put the body of your batch file here.
:
:endit
:19 "Roll your own" date format
:==================================================================
echo Display date in custom-made format: yymn3dd
Fdate /Ff /Oyy /V
Fdate /Ff /Omn3 /P"%fdate%" /V
Fdate /Ff /Odd /P"%fdate%" /V
echo Today is %fdate%
set fdate=
:20 Find the 4th Thursday in November (Thanksgiving)
:==================================================================
Fdate /Fw /D5 /N4 /A11-01-%year% /Imm-dd-ccyy /Od1 /P"Thanksgiving: "
:22 On a date, show what anniversary it is for some event
:==================================================================
See HOLIDAYS.BAT demo batch file
:23 Show a list of holidays in a given year
:==================================================================
See HOLIDAYS.BAT demo batch file
:24 Show a list of Federal holidays in a given year
:==================================================================
See HOLIFEDS.BAT demo batch file
:25 Determine if a year is valid, and evenly divisible by 4
:==================================================================
@echo off
cls
echo FUNCTION: Accept a year parm (CCYY) as parameter 1. Determine if
echo the year is an election or inauguration year in the United States.
echo ===================================================================
rem verify %1 is a valid year
Fdate /Fv /Imm-dd-ccyy /A01-01-%1 >nul
if errorlevel 1 echo Year parm [%1] is not valid.
if errorlevel 1 goto endit
Fdate /Ff /Imm-dd-ccyy /A01-01-%1 /p"@set year=">junktemp.bat
call junktemp.bat
Fdate /F#mod /A%1 /B4 /p"@set mod=">junktemp.bat
call junktemp.bat
if (%mod%)==(0) echo %1 is an American presidential election year.
if (%mod%)==(1) echo %1 is an American presidential inauguration year.
for %%v in (2 3) do if (%mod%)==(%%v) echo %1 is not an election year.
for %%v in (2 3) do if (%mod%)==(%%v) echo %1 is not an inauguration year.
set mod=
:endit
if exist junktemp.bat del junktemp.bat
:30 Compare a file's date to today's date
:==================================================================
rem Compare today's date to the date on the filename in %1
Fdate /Fcomp /At /If /B%1 /Vcomp
if (%comp%)==(EQ) echo %1 was created or updated today
set comp=
:32 Display a list of all files that were created/updated today.
:==================================================================
@echo off
if (%1)==(SUBROUTINE) goto %2
CLS
ECHO FILES MEETING FILESPEC [%1] THAT WERE CREATED OR UPDATED TODAY
REM The batch file calls itself: Its own name is in parm %0
for %%v in (%1) do CALL %0 SUBROUTINE CHECKFILE %%v
set comp=
goto endit
:CHECKFILE
shift
shift
rem Compare today's date to the date on the %1 file
Fdate /Fcomp /If /A%1 /Vcomp
rem echo the filename if the file was created/updated today
if (%comp%)==(EQ) echo %1
:endit
:33 Delete files more than X days old (use a batch-file subroutine)
:==================================================================
See the COMMENTARY that follows the text of the batch file.
@echo off
if (%1)==(SUBROUTINE) goto %2
cls
goto EndDoc
----------------------------------------------------------------------
OLDFILES.BAT
This batch file shows how to do work on files that are older than
%NumDays%. The PROCESS! subroutine can be modified to do any kind of
work you want.
----------------------------------------------------------------------
:EndDoc
:: set the number of days in the past. if this value is not passed
:: in via parameter %1, it defaults to 3 days
set NumDays=%1
if (%NumDays%)==() SET NumDays=3
echo ------------------------------------------------------------------
echo PROCESSING FILES CREATED MORE THAN %NumDays% DAYS AGO
echo ------------------------------------------------------------------
for %%v in (*.*) do CALL %0 SUBROUTINE PROCESS! %%v
echo ------------------------------------------------------------------
echo END OF PROCESSING
echo ------------------------------------------------------------------
:: CLEANUP
set NumDays=
set DaysOld=
set Comparison=
GOTO ENDIT
:
:PROCESS!
shift
shift
:: get difference in days between filedate and today.
:: Note that /B parm (which is omitted) defaults to today's date.
fdate /fdif /A%1 /IF /VDaysOld
:: compare DaysOld to NumDays
fdate /f#comp /A%DaysOld% /B%NumDays% /Vcomparison
:: the following line will DISPLAY THE NAME AND AGE OF
:: any file for which %DaysOld% is greater than %NumDays%
:: --------------------------------------------------------------
if (%comparison%)==(GT) echo %1 is %DaysOld% days old.
:: EXAMPLE (to activate this routine, remove the REM from column 1)
:: the following line will COPY TO AN ARCHIVE SUBDIRECTORY
:: any file for which %DaysOld% is greater than %NumDays%
:: -----------------------------------------------
REM if (%comparison%)==(GT) COPY %1 C:\ARCHIVE\*.*
:: EXAMPLE (to activate this routine, remove the REM from column 1)
:: the following line will DELETE
:: any file for which %DaysOld% is greater than %NumDays%
:: -----------------------------------------------
REM if (%comparison%)==(GT) DEL %1
:: fall through to endit
:endit
===============================================================
COMMENTARY BEGIN
===============================================================
This batch file uses a crude, but effective, technique for giving a
batch file the ability to call subroutines. If you've never seen
something like this before, it is sort of mind-blowing. Here's some
commentary on the more important lines involved in the technique.
===============================================================
if (%1)==(SUBROUTINE) goto %2
COMMENTARY:
If the first parameter, %1, is "SUBROUTINE", then the batch file
recognizes that it is being called for the purpose of executing
one of its own subroutines. In such a case, it does a GOTO to the
start of the requested subroutine. That is, it goes to the label
whose name is in the second parameter.
Explicitly specifying the name of the desired subroutine permits
permits us to have multiple subroutines in the batch file,
each with its own name. (As it happens, in this batch file
we have only one subroutine, named "PROCESS!")
If the first parameter is not "SUBROUTINE", then we fall through
and begin executing the main routine of the batch file. In such a
case, the first parameter (%1) may contain a number, indicating
the number of days to use in determining which files to delete.
Note that this technique will make the batch file malfunction
if the user himself ever executes the batch file from the
DOS command line with the word "SUBROUTINE" as the first
parameter, the word "PROCESS!" as the second parameter, and a
third parameter that is missing or not a valid filename.
This is so unlikely, however, that it is reasonable
to assume that it will never happen.
===============================================================
for %%v in (*.*) do CALL %0 SUBROUTINE PROCESS! %%v
COMMENTARY:
In a batch file, %0 contains the name by which the batch file was
invoked. We use this fact to allow a batch file to call itself,
regardless of what name the user has given to it.
The first parameter passed, when the batch file calls
itself, is the string "SUBROUTINE". This string allows the batch
file to recognize when it is being called for the purpose of
executing one of its own subroutines.
The second parameter is the name of the subroutine that we want
to call: in this case, "PROCESS!".
The third parameter is what we would normally think of as the first
parameter to the subroutine. In this case, when the
FOR statement is executed, and the substitution for %%v takes
place, it will contain the name of the file to be processed.
Note that we could, if we wished, pass additional parameters to
the subroutine. Note also that we can control the files that
we process. We do so via the filemask in the FOR statement.
It we used, for example, "*.EXE", then we would process only
executable files.
===============================================================
GOTO ENDIT
COMMENTARY:
When the mainline of the batch file is finished executing, we
goto the end of the batch file. We MUST do this GOTO in order
to avoid falling through into, and starting to execute, the first
of the batch file's subroutines.
===============================================================
:PROCESS!
shift
shift
COMMENTARY:
Note that when the batch file is called as a subroutine, and the
batch file goes to the PROCESS! label, the values of the parms are:
%0 = [the name of the batch file]
%1 = SUBROUTINE
%2 = PROCESS!
%3 = [name of the file to be processed]
We shift all the parmeters to the left twice, to move the
parameter(s) into what we think of as the
proper places for parameters to the subroutine.
After the first SHIFT command:
%0 = SUBROUTINE
%1 = PROCESS!
%2 = [name of the file to be processed]
After the second SHIFT command:
%0 = PROCESS!
%1 = [name of the file to be processed]
Now %1 contains what we think of as the proper parameter(s)
to the subroutine. In this case, %1 contains the filename that
we want the subroutine to process.
At the end of every subroutine, there should be a GOTO ENDIT,
which causes the batch file to go to its own end, and then
end and return control to the statement in the program which called
it. (This is, of course, the CALL statement embedded in the
FOR statement.)
We can optimize the batch file a little by omitting the "goto endit"
at the end of the last subroutine. Instead, we simply allow the
last subroutine to fall through to the end of the batch file.
===============================================================
COMMENTARY END
===============================================================
:34 Loop through an array of environment variables
:======================================================================
@echo off
cls
SET pct=%%%
SET prefix=Address
ECHO LOADING AN ARRAY
SET subscript=1
SET %prefix%.%subscript%=Stephen Ferg
SET subscript=2
SET %prefix%.%subscript%=5113 N. 8th Road
SET subscript=3
SET %prefix%.%subscript%=Arlington, VA 22205
ECHO UNLOADING AND DISPLAYING THE ARRAY
SET subscript=1
:LoopTop
REM do while subscript less than/equal 3
if %subscript%==4 goto LoopEnd
REM put value of subscripted variable into tempvar
ECHO SET tempvar=%pct%%prefix%.%subscript%%pct%>JUNKTEMP.BAT
CALL JUNKTEMP.BAT
REM display value of subscripted variable
ECHO %prefix%.%subscript% is: %tempvar%
REM delete subscripted variable
SET %prefix%.%subscript%=
REM increment the loop variable
Fdate /F#add /A%subscript% /B1 /Vsubscript
goto LoopTop
:LoopEnd
SET pct=
SET tempvar=
SET prefix=
SET subscript=
DEL JUNKTEMP.BAT
:44 Do something on the last day (or last Friday) of the month
:==================================================================
COMMENT
We often need batch files that do some special task on the last day of the
month: run a backup job, display a reminder message, etc. This example
batch file, LASTDAY.BAT, simply displays a message -- you can modify it to
do whatever it is that YOU want to do.
If you plan to run LASTDAY.BAT at work, and you work Monday through Friday,
then checking for the last day of the month would be a poor strategy --
after you leave work on a Friday, the last day of the month might occur on
the following Saturday or Sunday. So I've included a check to see if the
Friday is the last working day of the month. If you don't want that
functionality, deleting the lines between the first and last occurrence of
the string "EndCheck" will remove it.
=======================================================================
@echo off
REM ---------------------------------------------------------------
REM check to see if today is the last day of the month
REM ---------------------------------------------------------------
REM get today's month
fdate /ff /omm /vmmtoday
REM get tomorrow's month
fdate /fadd /n1 /omm /vmmtomorrow
REM if tomorrow occurs in a different month,
REM then today is the last day of this month
if not (%mmtoday%)==(%mmtomorrow%) echo LAST DAY OF THE MONTH
if not (%mmtoday%)==(%mmtomorrow%) goto EndCheck
REM -------------------------------------------------------------
REM check to see if today is the last Friday of the month
REM -------------------------------------------------------------
rem get today's day of the week, to see if it is Friday
fdate /ff /odow3 /vdow3
if not (%dow3%)==(Fri) goto EndCheck
REM today is Friday. Get next Monday's month
fdate /fadd /n3 /omm /vmmMonday
REM if next Monday occurs in a different month,
REM then today is the last Friday of this month
if not (%mmtoday%)==(%mmMonday%) echo LAST WORKING DAY OF THE MONTH
:EndCheck
REM cleanup
set dow3=
set mmtoday=
set mmtomorrow=
set mmMonday=
:45 Get information about the month prior to the current month
:==================================================================
COMMENT
When running a monthly backup job at the beginning of the month, one often
needs to identify the previous month, or the last day of the previous
month. Here's how to use Fdate to obtain that sort of information.
Basically, we subtract one day from the first day of the current month,
giving us the last day of the previous month.
=======================================================================
@echo off
cls
: The simplest way to get information about last month is to subtract
: 1 day from the first day of this month ...
fdate /fsub /n1 /att-01-tttt /omm /p"Last month was.................: "
fdate /fsub /n1 /att-01-tttt /occyy /p"Last month occurred in the year: "
fdate /fsub /n1 /att-01-tttt /odd /p"The last day of last month was : "
fdate /fsub /n1 /att-01-tttt /od1 /p"The last day of last month was : "
:51 Represent a date in a short (4-byte) format (technique #1)
:==================================================================
COMMENT
A common use of Fdate is to format today's date and use it to rename a file
(typically a log file of some sort). You may wish to store the date
information in as few characters as possible, in order to maximize the
number of other characters in the filename that you can use to store other
information.
In this example, and the next one, I illustrate two ways to store a date in
4 bytes.
The simplest way is to represent today's date as a 4-digit number.
To do this, we first pick a base date: I'll use January 1, 1990.
Then it is a simple matter to calculate the number of days between today
and the base date:
FDATE /Fdif /at /b01-01-1990
Starting in 1993, this will always generate a 4-digit number, and will
continue to do so for 20 years, until approximately the year 2003. Dates
before 1993 may produce 1-, 2-, or 3-digit numbers, and dates after 2003
will begin to produce 5-digit numbers. But this technique will work quite
nicely for most ordinary purposes for the next 20 years.
If you're still using DOS in the year 2003, then in 2003 you can switch to
using January 1, 2000 as your base date and function quite nicely for the
next 20 years after that.
:52 Represent a date in a short (4-byte) format (technique #2)
:==================================================================
@echo off
cls
goto end-doc
------------------------------------------------------------------
This batch file shows two ways to use Fdate and SetXX.BAT to
obtain and represent today's date in 4 characters, YYMD, where:
YY is the year (e.g. "93" for 1993)
M is the month in extended hexadecimal (XX) notation
D is the day-of-the-month in extended hexadecimal (XX) notation
The text of SetXX.BAT, and an explanation of extended hex notation,
can be found in the next example.
------------------------------------------------------------------
:end-doc
rem ----------------------------------------------------------------
rem VERSION 1 (using JUNK.BAT temporary batch file)
rem ----------------------------------------------------------------
REM OBTAIN 1-CHARACTER REPRESENTATION FOR THE MONTH
fdate /ff /omm /p"@call SetXX xm ">junk.bat
call junk.bat
echo XX representation of this month's number is %xm%
REM OBTAIN 1-CHARACTER REPRESENTATION FOR THE DAY
fdate /ff /odd /p"@call SetXX xd ">junk.bat
call junk.bat
echo XX representation of today's day of the month is %xd%
REM CONCATENATE THEM TO THE 2-CHARACTER REPRESENTATION FOR THE YEAR
fdate /ff /oyy /p"@set xx=" /s"%xm%%xd% >junk.bat
call junk.bat
echo XX representation of today's full date is %xx%
REM CLEANUP
set xm=
set xd=
set xx=
del junk.bat
echo.
:
echo.
rem ----------------------------------------------------------------
rem VERSION 2 (using JUNK environment variable)
rem ----------------------------------------------------------------
REM OBTAIN 1-CHARACTER REPRESENTATION FOR THE MONTH
fdate /ff /omm /p"call SetXX xm " /vjunk
%junk%
echo XX representation of this month's number is %xm%
REM OBTAIN 1-CHARACTER REPRESENTATION FOR THE DAY
fdate /ff /odd /p"call SetXX xd " /vjunk
%junk%
echo XX representation of today's day of the month is %xd%
REM CONCATENATE THEM TO THE 2-CHARACTER REPRESENTATION FOR THE YEAR
fdate /ff /oyy /p"set xx=" /s"%xm%%xd%" /vjunk
%junk%
echo XX representation of today's full date is %xx%
REM CLEANUP
set xm=
set xd=
set xx=
set junk=
echo.
echo.
:53 SetXX.BAT (used in the previous example)
:==================================================================
@echo off
goto end-doc
--------------------------------------------------------------------
"Extended hexadecimal" (XX) notation uses all of the digits, and
all of the letters of the alphabet, to express numbers in the range
of 0 to 35 as a single character. This batch file converts a 2-digit
number in the range of 00 to 35 to xx notation.
This batch file expects 2 parameters:
%1 contains the name of the environment variable that you
want to use to hold the xx value
%2 contains the 2-digit number that you want to convert to xx
--------------------------------------------------------------------
:end-doc
if (%2)==() goto endit
set %1=
if (%2)==(00) set %1=0
if (%2)==(01) set %1=1
if (%2)==(02) set %1=2
if (%2)==(03) set %1=3
if (%2)==(04) set %1=4
if (%2)==(05) set %1=5
if (%2)==(06) set %1=6
if (%2)==(07) set %1=7
if (%2)==(08) set %1=8
if (%2)==(09) set %1=9
if (%2)==(10) set %1=A
if (%2)==(11) set %1=B
if (%2)==(12) set %1=C
if (%2)==(13) set %1=D
if (%2)==(14) set %1=E
if (%2)==(15) set %1=F
if (%2)==(16) set %1=G
if (%2)==(17) set %1=H
if (%2)==(18) set %1=I
if (%2)==(19) set %1=J
if (%2)==(20) set %1=K
if (%2)==(21) set %1=L
if (%2)==(22) set %1=M
if (%2)==(23) set %1=N
if (%2)==(24) set %1=O
if (%2)==(25) set %1=P
if (%2)==(26) set %1=Q
if (%2)==(27) set %1=R
if (%2)==(28) set %1=S
if (%2)==(29) set %1=T
:
if (%2)==(30) set %1=U
if (%2)==(31) set %1=V
if (%2)==(32) set %1=W
if (%2)==(33) set %1=X
if (%2)==(34) set %1=Y
if (%2)==(35) set %1=Z
:endit
:54 Customize Fdate for a language of your choice
:==================================================================
@echo off
cls
goto end-doc
------------------------------------------------------------------
You can use Fdate with a customized batch file to obtain the names of
the days of the week and the months in a language of your choice. Or
you could use it to obtain names in uppercase, or the first 5
characters of the names (rather than the first three), or some other
customized formatting of your choice.)
I've invented a language called Fergian, which has its own names for
the days of the week, and the months. In the following examples, I
invoke FERGIAN.BAT to make the translation. The text of FERGIAN.BAT,
which does the real work here, is given in the next example.
------------------------------------------------------------------
:end-doc
fdate /ff /omm /v
call Fergian mm- result %Fdate%
echo Month is %result%
fdate /ff /omm /v
call Fergian mm3 result %Fdate%
echo Month3 is %result%
fdate /ff /odow# /v
call Fergian dw- result %Fdate%
echo Day of week is %result%
fdate /ff /odow# /v
call Fergian dw3 result %Fdate%
echo Day of week3 is %result%
REM cleanup
set Fdate=
set result=
:55 Fergian.BAT (used in the previous example)
:==================================================================
@echo off
set %2=
goto %1
goto end-doc
--------------------------------------------------------------------
This batch file converts a month number, or day of the week number,
to a name in the FERGIAN language.
You can copy this batch file and customize it, to make it translate
into some other language of your choice.
This batch file expects the following parameters:
%1 contains the type of number you want to convert:
MM- if you want the entire name of the month
MM3 if you want the first 3 letters of the name of the month
DW- if you want the entire name of the day of the week
DW3 if you want the first 3 letters of the name of the day of the week
%2 contains the name of the environment variable that you
want to use to hold the result
%3 contains the number that you want to convert
--------------------------------------------------------------------
:end-doc
:MM-
if (%3)==(01) set %2=Jaded
if (%3)==(02) set %2=Febrile
if (%3)==(03) set %2=Martial
if (%3)==(04) set %2=Abigail
if (%3)==(05) set %2=Maybelene
if (%3)==(06) set %2=Junkaroo
if (%3)==(07) set %2=Julia
if (%3)==(08) set %2=Augmentation
if (%3)==(09) set %2=Separation
if (%3)==(10) set %2=Ostentation
if (%3)==(11) set %2=Novelty
if (%3)==(12) set %2=Decadence
goto endit
:
:MM3
if (%3)==(01) set %2=Jad
if (%3)==(02) set %2=Feb
if (%3)==(03) set %2=Mar
if (%3)==(04) set %2=Abi
if (%3)==(05) set %2=May
if (%3)==(06) set %2=Jun
if (%3)==(07) set %2=Jul
if (%3)==(08) set %2=Aug
if (%3)==(09) set %2=Sep
if (%3)==(10) set %2=Ost
if (%3)==(11) set %2=Nov
if (%3)==(12) set %2=Dec
goto endit
:DW-
if (%3)==(1) set %2=SunDay
if (%3)==(2) set %2=MoonDay
if (%3)==(3) set %2=TwickasDay
if (%3)==(4) set %2=WodensDay
if (%3)==(5) set %2=ThorsDay
if (%3)==(6) set %2=FreyasDay
if (%3)==(7) set %2=SaturnDay
goto endit
:DW3
if (%3)==(1) set %2=Sun
if (%3)==(2) set %2=Moo
if (%3)==(3) set %2=Twi
if (%3)==(4) set %2=Wod
if (%3)==(5) set %2=Tho
if (%3)==(6) set %2=Fre
if (%3)==(7) set %2=Sat
goto endit
:endit
:61 DO-ONCE: Run apps when booting for the first time of the day
:===============================================================
COMMENT
Put this code in AUTOEXEC.BAT. Note that this batch code requires DOS
3.3+, since it uses CALL.
if not exist C:\LASTRUN.BAT goto RunNow
rem call LASTRUN.BAT, which will set an environment variable, %LASTRUN%,
rem that will contain the date when this batch file was last run.
rem ------------------------------------------------------------------
call C:\LASTRUN.BAT
rem compare the date in %LASTRUN% to today's date
rem ------------------------------------------------------------------
Fdate /Fcomp /At /B%LastRun% /Vcomp
: Today's date may be less than %LASTRUN% if you reset the system clock
IF (%COMP%)==(LT) goto NoRun
: If %LASTRUN% was the same as today's date,
: then this batch file has already been run once today
IF (%COMP%)==(EQ) goto NoRun
: Daily processing hasn't been run today. Run it.
: Here, you should put the batch-file body --
: the code to run the applications that you want to run once per day
:
: ------------------------------------------------------------------
: Save today's date in a new version of LastRun.BAT. Note that
: this code will be executed only if daily processing runs to
: completion without hanging the machine or aborting the batch file.
: ------------------------------------------------------------------
Fdate /Ff /Omm-dd-ccyy /At /P"@set LastRun=">LastRun.BAT
:NoRun
set LastRun=
set COMP=
:62a Run specific software, depending on the day of the week
:==================================================================
COMMENT
This is a very common use for Fdate. I use it to load alarm-clock software
that will beep at me -- at different times for different days of the week -
- to remind me that it is time to attend a regular weekly meeting that is
scheduled for that day of the week.
Note that stuff for a given day of the week will be executed every time
you boot up on that day of the week. That is what you want if, like me,
you are loading alarm-clock software.
If your application is different, and you want stuff for a given day of the
week to be run only once -- the first time you boot up each day --then
first copy the code from DO-ONCE (the previous example) into your
AUTOEXEC.BAT file, then put this code into AUTOEXEC.BAT in the body of the
DO-ONCE code. If you do that, then this code will be run only once per
day, even if you boot up multiple times per day.
Remember that if you are executing other batch files from a batch file,
you probably want to invoke them with a CALL statement:
CALL batchfilename parm1 parm2 ...
so control will return to the calling batch file when execution of the
called batch file is complete.
========================================================================
rem get 3-character day-of-week name and put it in DOW e-var
FDATE /ff /oDOW3 /vDOW
goto %DOW%
:MON
:
: Here, put code to run stuff for this day of the week.
: for example: CALL MONDAY.BAT
:
goto END-DOW
:FRI
:
: Here, put code to run stuff for this day of the week.
:
goto END-DOW
rem do nothing on the following days -- fall through to END-DOW
:SAT
:SUN
:TUE
:WED
:THU
:END-DOW
set dow=
:62b Run specific software, depending on the day of the week
:==================================================================
COMMENT
This is a variation on the last example. Note that the string
comparison is case sensitive.
rem get 3-character day-of-week name and put it in DOW e-var
FDATE /ff /oDOW3 /vDOW
if (%DOW%)==(Mon) echo Running regular Monday backup. Please wait...
if (%DOW%)==(Mon) CALL BACKUP C:
if (%DOW%)==(Mon) CALL BACKUP D:
if (%DOW%)==(Mon) CALL BACKUP E:
if (%DOW%)==(Mon) CALL BACKUP F:
if (%DOW%)==(Thu) echo Running regular Thursday backup. Please wait...
if (%DOW%)==(Thu) CALL BACKUP C:
if (%DOW%)==(Thu) CALL BACKUP F:
set dow=
:63 Run a program at a specified time later in the day
:==================================================================
COMMENT
This batch file involves a lot of disk activity because DOS re-reads the
batch file from disk every time it does a GOTO LOOPTOP. You can avoid
all this disk activity by running the batch file from a RAM DISK.
REM GET CURRENT ABSOLUTE MINUTE AND PUT IN ENVIRONMENT VARIABLE RUNTIME
FDATE /Ff /At /Ominute# |STRINGS RunTime= ASK >NUL
REM ADD 120 MINUTES (2 HOURS) TO ENVIRONMENT VARIABLE RUNTIME
FDATE /F#add /A%RunTime% /B120 |STRINGS RunTime= ASK >NUL
REM LOOP UNTIL NOWTIME HAS REACHED RUNTIME
:LoopTop
FDATE /Ff /At /Ominute# |STRINGS NowTime= ASK >NUL
FDATE /F#comp /A%NowTime% /B%RunTime% |STRINGS TimeComp= ASK >NUL
if (%TimeComp%)==(LT) goto loopTop
:LoopEnd
echo STARTING EXECUTION OF APPLICATION: [program name]
:67 Change a file's name to a name that contains today's date
:==================================================================
FDATE /Ff /Atoday /Oyymmdd /vdate1
ren BACKUP.LOG BK%DATE1%.LOG
SET DATE1=
:68 Change a file's name to a name containing an absolute minute
:===============================================================
COMMENT
This is a way to keep a complete series of files, such as log files,
that are all created with the same name on the same day. The only
requirement is that they be created at least one minute apart. You
won't need to be able to decipher the absolute minute to figure out when
the file was created; you can simply do a DIR on the file and look at
its date/time stamp.
FDATE /FF /At /Ominute# /VJulMin
REN online.log %JulMin%.log
SET JulMin=
HOW FDATE THINKS ABOUT DATES
============================
FDATE'S BUSINESS VIEW OF THE CALENDAR
=====================================
FDATE is intended for business applications, not historical ones.
FDATE does not take into account historical changes in the calendar such
as the ten days that were dropped from the British calendar when Britain
moved from the Julian to the Gregorian calendar in the 18th century, or
the 11 days that were dropped from the Russian calendar when Russia made
the same move in the early 20th century.
As far as FDATE is concerned, the calendar has followed the same
pattern, unchanged, since January 1, 0001.
FDATE'S BASE DATE
=================
Internally, Fdate's date manipulations are based on translating a
calendar date into an "absolute" or "TRUE Julian" date: a date
expressed as the number of days from some day in the distant past.
FDATE's base date is January 1, 0001 (i.e. day 1 of month 1 of year 1)
FDATE's absolute date for January 1, 0001 is 1.
FDATE's absolute date for January 1, 1992 is 727198.
FDATE'S LEAP YEAR ALGORITHM
===========================
Every year evenly divisible by 4 IS a leap year
EXCEPT THAT
Every year evenly divisible by 100 IS NOT a leap year
EXCEPT THAT
Every year evenly divisible by 400 IS a leap year
.
Using this algorithm
1983 is not a leap year
1984 is a leap year
1900 is not a leap year
2000 is a leap year
See "A Machine Algorithm for Processing Calendar Dates", by
Henry F. Fliegel (Georgetown University Observatory) and
Thomas C. Van Flandern (U.S. Naval Observatory)
COMMUNICATIONS OF THE ACM, Volume 11, Number 10, October 1968
There is supposedly a new adjustment to the leapyear algorithm,
which specifies the additional exception:
EXCEPT THAT
Every year evenly divisible by 4000 IS a leap year
See "Bit By Bit" column, COMPUTER LANGUAGE, November 1989, p. 148.
This adjustment is not part of FDATE's leapyear algorithm.
Unless your application is working with dates 2,000 years in the
future, the lack of this exception will be irrelevant for you.
FDATE'S CENTURY-ASSUMPTION ALGORITHM
====================================
If an input date is supplied in a format in which the year is
specified without a century -- that is, as YY rather than CCYY --
then Fdate does not automatically use the current century.
Instead,
* if YY is greater than 20, then FDATE assumes CC = 19
* if YY is less than or equal 20, then FDATE assumes CC = 20
Examples:
21 becomes 1921
...
99 becomes 1999
00 becomes 2000
01 becomes 2001
...
20 becomes 2020
but then (again)
21 becomes 1921
To put it simply, FDATE makes what would be a reasonable assumption
about the century for someone operating in the 1990's: it looks back to
1921 and forward to 2020. If both I and FDATE are still alive in the
year 2000, I'll probably update FDATE's century-assumption algorithm to
shift it forward several decades.
FDATE'S IMPLEMENTATION LIMITS
====================================
Internally, numbers in Fdate are stored in Turbo Pascal's LONGINT datatype,
which means that Fdate can accept numbers up to 9 digits long.
DISTRIBUTION ISSUES
===================
USE, REGISTRATION, AND DISTRIBUTION OF FDATE
============================================
FDATE is freeware, or what is known as "zero-cost shareware". FDATE is not
what is technically called "public domain" software because the author
retains the copyright. FDATE can, however, be copied, used, and
distributed freely as long as FDATE.EXE and its associated doc file
(FDATE.DOC), along with its demonstration batch files and their doc files
(FDATEX.BAT, HOLIDAYS.BAT, HOLIFEDS.BAT, HOLIFEDS.DOC, TIC.BAT, ALARM.BAT,
etc.) are not altered and are distributed together.
There is no requirement to register FDATE in any way.
FDATE can be included in shareware packages as long as both FDATE and
its related files are included in the shareware package.
If you have received FDATE as part of some larger shareware package,
please be aware that you may freely use, copy, and distribute FDATE
without paying a fee for, or registering, the larger package.
The author explicitly disavows any claim whatsoever about the
correctness or functionality of FDATE, its documentation, and its
demonstration batch files, and disclaims liability for anything and
everything bad that might happen in connection with, before, during, or
after using it. I have tried to make FDATE work right, but everybody
makes mistakes, so you use FDATE at your own risk.
I don't know if people will find FDATE useful, and I'd like to find
out. If you find FDATE useful and use it on a regular basis, I'd
appreciate it if you would drop me a short note via US mail or
CompuServe, telling me about how you are using FDATE.
If you need other input/output formats, please contact the author.
TECHNICAL SUPPORT FOR FDATE
===============================================
Send me a message via CompuServe mail; I'll respond. When sending your
message, please let me know what version of Fdate you're using.
WHERE TO FIND THE MOST CURRENT VERSION OF FDATE
===============================================
You will always be able to find the most recent version of FDATE on
CompuServe. The filename will be FDATE.ZIP, and it will be available in
the CIS:IBMSYS forum (library 1, the "DOS Utilities" library).
If you have problems finding it, try using cross-library searching, looking
for the filename FDATE.ZIP or the keyword FDATE.
UPLOADING FDATE TO ELECTRONIC BULLETIN BOARDS
===============================================
Feel free to post copies of FDATE.ZIP on any BBS that you wish, but please
do not upload it to any CompuServe library. As long as I am the only one
putting copies of FDATE onto CompuServe, we can keep confusion over
versions to a minimum.
DEMONSTRATION BATCH FILES
=========================
FDATE ships with a number of demonstration batch files. These are sample
applications that illustrate some of the ways that FDATE might be used to
build applications. They can be studied for ideas for ways of using FDATE.
They can also be used "as is", or copied and customized to build
applications that meet your own special needs.
CONTENTS OF THE FDATE.ZIP DISTRIBUTION FILE
===========================================
The current distribution package (FDATE.ZIP) contains the following:
FDATE.EXE [the FDATE program]
FDATE.DOC [this file, documentation for FDATE]
[demonstration batch files]
FDATEX.BAT
HOLIDAYS.BAT
HOLIFEDS.BAT and HOLIFEDS.DOC
ALARM.BAT and ALARM.DOC
TIC.BAT and TIC.DOC
FDATE REVISION HISTORY
======================
Letters appended to version numbers indicate modifications to
the doc files, without any modification to the FDATE.EXE software.
Asterisks (*) indicate most important changes in the new version.
Most of the revision history before version 6.7 has been omitted, as not
being of general interest.
3.0a Dec 27, 1991
* =============== MAJOR BUG FIX ==============================
* Fixed bug in TRUEDATE date arithmetic routine that caused
* incorrect dates to be returned for the last 2 or 3 days of
* some months.
* ============================================================
6.7a Apr 05, 1992
* Added function "E" (echo)
* Added output format: "dd mn3 yy" EXAMPLE: 05 Sep 92
Added JDATE.BAT example batch file, thanks to Aran Spence.
Corrected a bug in the routine that obtained command line
parameters. It sometimes caused an improper value to be
returned if a quoted parameter did not contain a space.
6.8a Aug 01, 1992
* I will no longer be posting the most recent version of FDATE
in ZNT:UTILFORUM because ZiffNet's new fees would require me
to pay $30/year to do so. Look for the most recent version
of FDATE in CIS:IBMSYS, Library 1.
* Added output format: ddmn3yy EXAMPLE: 05Sep92
* Added output format: yy EXAMPLE: 92
This should make it easier for users to "roll their own"
date formats. See the "roll your own" example.
* Modified documentation in JDATE.BAT to make it clear that it
is working with a BUSINESS julian date format: YYjjj.
Thanks for the feedback from Howard S. Friedman (70720,3022)
Updated FDATEX.BAT to test the new formats.
6.8b Aug 02, 1992
Added example showing how to get last Friday's date using /Fw
Modified JDATE.BAT so it describes its Julian date as a 'business
julian' date.
6.8c Aug 07, 1992
Revised the discussion of "tt" and "tttt" in output formats to make
it more compact. Again, thanks for the feedback from Howard S.
Friedman (70720,3022).
7.0a Nov 14, 1992
* Fixed bug in which 10-character Spanish-language month-names were
being truncated to 9 characters.
* Added #mod function
* Major reformatting of documentation to make it more user-friendly
Removed DO-ONCE.BAT from distribution ZIP file, as it was already
documented in an example in this doc file.
Added HOLIFEDS.BAT and HOLIFEDS.DOC to the distribution ZIP file.
Calculates Federal holidays in a given year.
VERSION 7.3a RELEASED
7.0b Dec 15, 1992
Corrected last few lines of HOLIFEDS.DOC, which referred to
Dec 24, 1964 as a Friday. It was a Thursday.
7.1a Apr 15, 1993
Added German language parm (/Lgr). Thanks for the request, and the
necessary information, from Patrick Schmucki, via the Active-Net
BBS in Rapperswil, Switzerland.
7.1b Apr 20, 1993
Added LASTDAY.BAT example. Thanks to Patrick Boyle for the request
for an explanation of how this might be done.
7.1c Apr 28, 1993
In an attempt to improve the helpfulness of the documentation,
moved the detailed description of functions closer to the beginning
of this doc file, and added a one-page OVERVIEW OF FUNCTIONS.
7.2a May 1, 1993
Corrected German-language name for month of March from "Mrz" to
"März"
7.3a May 25, 1993
Added output formats "zd. mn ccyy" and "zd. mn3 ccyy" for the
convenience of German-speaking users. Thanks for the request from
Patrick Schmucki.
Added output format ZM.
To this .DOC file, added:
Examples of how to represent a date in 4 bytes, along with the text
of SETXX.BAT, and example of how to get information about the month
prior to the current month. Thanks to Richard Beels for the
request for ideas on how to do this sort of thing.
7.3b May 29, 1993
To this .DOC file, added:
Example of how to use a batch file (FERGIAN.BAT) to customize Fdate
for a different language, using a technique similar to SETXX.BAT.
Thanks to Sebastian Bazley, of the Higher Education National
Software Archive at Lancaster University, UK, for suggestions that
got me started thinking along these lines.
VERSION 7.3b RELEASED
7.4a July 7, 1993
* Add "V" (validate) function: /Fv
Restructured HELP screen into several screens, because the single
HELP screen was getting too crowded.
7.5a July 9, 1993
Added error checking for input dates that contain a month
specification that is less than 1 or greater than 12
7.6a July 9, 1993
Added "m" (month addition/subtraction) function: /Fm
7.7a July 10, 1993
Added "#mult" (multiplication) function: /F#mult
Added "#div" ( division) function: /F#div
Added "#idiv" (integer division) function: /F#idiv
7.8a July 14, 1993
Added /T (time) parameter
Changed value that /Fv produces for an OK date from "OK" to the
null string. This should make it a little easier to use.
Removed the TIMER demo from FDATEX.BAT, since it is now in this DOC
file.
7.9a July 15, 1993
Minor change to the monthly arithmetic code to improve clarity
Added error-trapping routines for numeric input parameters that
exceed 9 digits, and for results of multiplication operations that
overflow limits of Turbo Pascal's LONGINT datatype
8.0a July 15, 1993
Added FORATIME.BAT example, which Walter Ledge (assistant sysop of
CompuServe's CRFORUM) and I developed. A big thanks to Walt for
his feedback, which provided the spark I needed to add the /Time
parameter and the #idiv function.
Added JDATE.BAT to the list of examples in this doc file, and
removed it from the files included in the .ZIP distribution file.
VERSION 8.0a RELEASED
8.1a July 27, 1993
Bug fix.
An error error-trapping routine that was added to Fdate version 7.9
contained a bug caused in part by a programmer error and in part by
some extremely strange behavior of the Turbo Pascal compiler
itself. The bug caused of Fdate's numeric math functions (#add,
#dif, #mult, #div, #idiv, #mod, #comp, etc.) -- all of which use
the new error-trapping routine -- to return incorrect results.
Thanks to Bob Schuchman for the quick bug report.
VERSION 8.1a RELEASED
8.1b August 6, 1993
Removed FILEDATE.BAT from the distribution .ZIP file.
Added OLDFILES.BAT, a simplified version, to this .DOC file
8.1c August 8, 1993
Added commentary on OLDFILES.BAT.
8.2a August 13, 1993
Corrected the Spanish and French "full" and "d1" output formats.
Thanks for the information on Spanish and French date formats to
Gene J. Raymond, of GJR Software Products.
VERSION 8.2a RELEASED