home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Media Share 13
/
mediashare_13.zip
/
mediashare_13
/
ZIPPED
/
UTILS
/
FDATE84A.ZIP
/
FDATE.DOC
< prev
next >
Wrap
Text File
|
1994-03-25
|
125KB
|
3,209 lines
FDATE Version 8.4a March 20, 1994
======================================================================
AUTHOR: Stephen Ferg
5113 N. 8th Road
Arlington, VA 22205-1201
USA
telephone (voice, not FAX): (703) 525-2241
CompuServe ID : 73377,1157
Internet : 73377.1157@compuserve.com
=======================================================================
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?. . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
OTHER UTILITIES NAMED "FDATE". . . . . . . . . . . . . . . . . . . 5
OVERVIEW OF PARAMETERS . . . . . . . . . . . . . . . . . . . . . . 6
OVERVIEW OF FUNCTIONS. . . . . . . . . . . . . . . . . . . . . . . 8
FUNCTIONS: DETAILED DESCRIPTIONS. . . . . . . . . . . . . . . . . . . 10
DATE FORMATTING FUNCTIONS. . . . . . . . . . . . . . . . . . . . . 10
DATE ARITHMETIC FUNCTIONS. . . . . . . . . . . . . . . . . . . . . 11
MONTH DATE ARITHMETIC FUNCTIONS. . . . . . . . . . . . . . . . . . 12
WEEKDAY DATE ARITHMETIC FUNCTIONS. . . . . . . . . . . . . . . . . 13
DATE/TIME COMPARISON FUNCTIONS . . . . . . . . . . . . . . . . . . 14
COMPARE-FUNCTION ERRORLEVELS . . . . . . . . . . . . . . . . . . . 14
NUMERIC ARITHMETIC FUNCTIONS . . . . . . . . . . . . . . . . . . . 15
DATE VALIDATION FUNCTION . . . . . . . . . . . . . . . . . . . . . 17
STRING FUNCTIONS. . . . . . . . . . . . . . . . . . . . . . . . . . . 18
GET and GETU (GET USER INPUT) FUNCTION . . . . . . . . . . . . . . 18
GETK (GET KEYPRESS) FUNCTION . . . . . . . . . . . . . . . . . . . 19
Specifying the Keymask . . . . . . . . . . . . . . . . . . . . . 19
GetK Results also in ERRORLEVEL. . . . . . . . . . . . . . . . . 20
Modifying the Keymask. . . . . . . . . . . . . . . . . . . . . . 21
Displaying a User Prompt With GETK . . . . . . . . . . . . . . . 21
SUBSTR (SUBSTRING) FUNCTION. . . . . . . . . . . . . . . . . . . . 22
LEN (LENGTH) FUNCTION. . . . . . . . . . . . . . . . . . . . . . . 23
UPPER FUNCTION . . . . . . . . . . . . . . . . . . . . . . . . . . 23
ECHO FUNCTION. . . . . . . . . . . . . . . . . . . . . . . . . . . 23
DATE FORMATS. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
SYMBOL CONVENTIONS . . . . . . . . . . . . . . . . . . . . . . . . 24
PSEUDODATES. . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
INPUT DATE FORMATS. . . . . . . . . . . . . . . . . . . . . . . . . . 26
CALENDAR DATE INPUT FORMATS. . . . . . . . . . . . . . . . . . . . 26
BUSINESS JULIAN DATE INPUT FORMATS . . . . . . . . . . . . . . . . 27
GETTING DATE/TIME A FILE WAS CREATED . . . . . . . . . . . . . . . 28
OUTPUT DATE FORMATS . . . . . . . . . . . . . . . . . . . . . . . . . 29
DAY-OF-WEEK AND MONTH OUTPUT FORMATS . . . . . . . . . . . . . . . 31
MISCELLANEOUS OUTPUT FORMATS . . . . . . . . . . . . . . . . . . . 31
LEAP-YEAR FLAG OUTPUT FORMAT . . . . . . . . . . . . . . . . . . . 32
TIME OUTPUT FORMATS. . . . . . . . . . . . . . . . . . . . . . . . 32
BUSINESS JULIAN DATE OUTPUT FORMATS. . . . . . . . . . . . . . . . 33
ABSOLUTE DATE/TIME OUTPUT FORMATS. . . . . . . . . . . . . . . . . 34
/T: TIME OVERRIDE PARAMETER. . . . . . . . . . . . . . . . . . . . 35
HOW TO PUT FDATE OUTPUT INTO AN ENVIRONMENT VARIABLE. . . . . . . . . 36
CALL A BATCH FILE. . . . . . . . . . . . . . . . . . . . . . . . . 36
USE AN ENVIRONMENT-MANIPULATION UTILITY. . . . . . . . . . . . . . 36
FDATE'S /V PARAMETER . . . . . . . . . . . . . . . . . . . . . . . 37
/V WHEN RUNNING UNDER MICROSOFT WINDOWS. . . . . . . . . . . . . . 38
Turbo Professional: "Highly Recommended" . . . . . . . . . . . . 38
/V WHEN USING 4DOS, NDOS, AND UMB. . . . . . . . . . . . . . . . . 39
FDATE'S ERROR HANDLING. . . . . . . . . . . . . . . . . . . . . . . . 40
EXAMPLES OF HOW TO USE FDATE. . . . . . . . . . . . . . . . . . . . . 41
:01 Display Fdate output on screen . . . . . . . . . . . . . . . . 41
:02 Redirect FDATE output to a file. . . . . . . . . . . . . . . . 41
:03 Put FDATE output in an environment variable using a batch file 41
:04 Put FDATE output in an environment variable using /V parm. . . 41
:05 Put FDATE output in an environment variable using STRINGS. . . 41
:06 Put FDATE output in an environment variable using GET. . . . . 41
:07 Change a date from one format into another . . . . . . . . . . 41
:07 Get user input . . . . . . . . . . . . . . . . . . . . . . . . 42
:08 Get a user menu selection. . . . . . . . . . . . . . . . . . . 43
:11 Find the difference in days between two dates. . . . . . . . . 44
:12 Find the elapsed days/hours/minutes between two date/times . . 45
:13 FORATIM2.BAT . . . . . . . . . . . . . . . . . . . . . . . . . 48
:14 Time the execution of a piece of software. . . . . . . . . . . 51
:15 Find calendar date corresponding to a "business Julian" date . 53
:16 Set your PC's date to a business julian date . . . . . . . . . 54
:18 Determine if parm %1 contains a valid date . . . . . . . . . . 56
:19 "Roll your own" date format . . . . . . . . . . . . . . . . . 57
:20 Find the 4th Thursday in November (Thanksgiving) . . . . . . . 57
:22 On a date, show what anniversary it is for some event. . . . . 57
:23 Show a list of holidays in a given year. . . . . . . . . . . . 57
:24 Show a list of Federal holidays in a given year. . . . . . . . 57
:25 Determine if a year is valid, and evenly divisible by 4. . . . 58
:30 Compare a file's date to today's date. . . . . . . . . . . . . 58
:31 Compare two files' date/time . . . . . . . . . . . . . . . . . 59
:32 Display a list of all files that were created/updated today. . 60
:33 Delete files more than X days old (use a batch-file subroutine) 61
:34 Loop through an array of environment variables . . . . . . . . 66
:44 Do something on the last day (or last Friday) of the month . . 67
:45 Get information about the month prior to the current month . . 68
:50 Represent a date in 3 bytes of "extended hex" notation . . . . 69
:51 Represent a date in a short (4-byte) format (technique #1) . . 69
:52 Represent a date in a short (4-byte) format (technique #2) . . 70
:54 Customize Fdate for a language of your choice. . . . . . . . . 71
:55 Fergian.BAT (used in the previous example) . . . . . . . . . . 72
:58 Convert numbers to . . . . . . . . . . . . . . . . . . . . . . 74
:61 DO-ONCE: Run apps when booting for the first time of the day . 75
:62 Run specific software, depending on the day of the week. . . . 76
:63 Run a program at a specified time later in the day . . . . . . 76
:66 Change a filename to contain today's date. . . . . . . . . . . 78
:67 Change a file's name to a name that contains today's date. . . 78
:68 Change a file's name to a name containing an absolute minute . 78
:71 Extract the rightmost n characters of a string . . . . . . . . 79
HOW FDATE THINKS ABOUT DATES. . . . . . . . . . . . . . . . . . . . . 80
FDATE'S BUSINESS VIEW OF THE CALENDAR. . . . . . . . . . . . . . . 80
FDATE'S BASE DATE. . . . . . . . . . . . . . . . . . . . . . . . . 80
FDATE'S LEAP YEAR ALGORITHM. . . . . . . . . . . . . . . . . . . . 81
FDATE'S CENTURY-ASSUMPTION ALGORITHM . . . . . . . . . . . . . . . 82
FDATE'S IMPLEMENTATION LIMITS. . . . . . . . . . . . . . . . . . . 82
DISTRIBUTION ISSUES . . . . . . . . . . . . . . . . . . . . . . . . . 83
USE, REGISTRATION, AND DISTRIBUTION OF FDATE . . . . . . . . . . . 83
TECHNICAL SUPPORT FOR FDATE. . . . . . . . . . . . . . . . . . . . 84
WHERE TO FIND THE MOST CURRENT VERSION OF FDATE. . . . . . . . . . 84
UPLOADING FDATE TO ELECTRONIC BULLETIN BOARDS. . . . . . . . . . . 84
CONTENTS OF THE FDATE.ZIP DISTRIBUTION FILE. . . . . . . . . . . . 84
RECENT FDATE REVISION HISTORY. . . . . . . . . . . . . . . . . . . 85
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.
accept user input from the keyboard
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
extract a substring from an environment variable
OTHER UTILITIES NAMED "FDATE"
=============================
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 /Q
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.
What parameters are required (other than /F) depends 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 For date functions, these two parameters are used to specify dates.
/B 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.
/Q specifies a prompt string for a GET, GETU, or GETK function, or the
input string for a string-handling function (SUBSTR, LEN, UPPER).
/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 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.
If the /F parameter is omitted, it defaults to the null string, which
causes Fdate to display its HELP screens.
f Format the date in the /A parm into format specified in /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
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.
m Do date arithmetic in terms of months rather than days. Add the
number of months in the /N parm to the date in the /A parm. /N
may be a negative number.
STRING-HANDLING FUNCTIONS
get get user input from the keyboard, and produce it as output
Optionally, display a prompt string.
getu same as get, but produce output converted to upper case
getk get a keypress and produce it (converted to upper case)
len produce the length of a string in the /Q parm
upper convert the string in the /Q parm to upper case
e Echo the strings on the /P and /S parameters.
substr Extract a substring from the /Q parm, starting in column
specified on /A parm, for a length specified on /B parm.
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.
#2xx Convert an integer in the range of 0-35 to "extended hex" (XX)
notation.
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 [month arithmetic]
This function adds /N months to /Adate, and produces a date in
/Oformat format. It can 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 [week arithmetic]
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 /V
FDATE /Fw /A%fdate% /Imm-dd-ccyy /D6 /N-2 /V
Echo Last Friday was %fdate%
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
In addition, the errorlevel is set to a special value:
LT = 101 EQ = 102 GT = 103
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
In addition, the errorlevel is set to a special value:
LT = 101 EQ = 102 GT = 103
COMPARE-FUNCTION ERRORLEVELS
============================
Starting with version 8.3, Fdate's "comparison" functions (comp, tcomp,
#comp) return distinct errorlevels as well as distinct output strings:
returns errorlevel
LT 101
EQ 102
GT 103
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
In addition, the errorlevel is set to a special value:
LT = 101 EQ = 102 GT = 103
#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.
#2xx (convert number to "extended hex" format)
"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 function takes a number supplied on parameter /A, and
returns a single character in extended hex notation. The input
number should be in the range of 0-35. A number of less than 0
or larger than 35 is rejected as an error (returns "ERROR" and
errorlevel of 1).
EXAMPLE: Fdate /F#2xx /A35 =====> returns the letter Z
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 using the /Fv parameter, you will almost always want to check
success of the date validation by checking the errorlevel, and to
redirect Fdate's output to NUL (so that when it writes the null
string, it does not produce a blank line on your screen).
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.
STRING FUNCTIONS
================================
GET and GETU (GET USER INPUT) FUNCTIONS
=======================================
get get user input
getu get user input (uppercase)
These functions wait for the user to enter an input string, terminated
by a press of the ENTER key. Then Fdate simply produces that same
input string (or in the case of GETU, that input string in all upper
case) as its output.
If the /Q prompt-string parameter is specified, then the prompt string
is displayed, but a NEWLINE is not written to the screen before
waiting for the user's input.
As with Fdate's other forms of output, this output can be displayed,
redirected to a file, or (if your environment supports Fdate's /V
parameter) placed into an environment variable.
This "get" function provides no edit mask for input -- Fdate will
accept anything. The situation is helped by the fact that Fdate also
provides a validate function (/Fv) which can be used to validate the
user input, so that one can:
1. use /Fget to get user input and place it in an environment
variable
2. use /Fv to validate the date in the Evar
3. use the rest of the batch file to process the user input
See examples: "Get user input" and FORATIM2.BAT
For a program that provides more sophisticated functions for getting
user input in batch files (type checking, edit masks, etc.), I
recommend Bob Stephan's shareware program GET, which is described
elsewhere in this documentation.
GETK (GET KEYPRESS) FUNCTION
=======================================
getK get keypress
This function waits for the user to press an acceptable key, then
produces the key as its output. If the key pressed is a letter, then
the letter is returned IN UPPER CASE. This feature is designed to
support simple "pick a menu selection" processing in batch files.
The GETK function takes a /K "keymask" parameter that tells it which
keys to accept. If the user presses an unacceptable key (i.e. one
that is not in the keymask), the keypress is ignored.
If no /K parm is specified, the default keymask is:
ABCDEFGHIJKLMNOPQRSTUVWXYZx
That is, the default keymask will accept letters and the ESCAPE key.
Specifying the Keymask
NOTE THAT THE VALUES SPECIFIED ON THE /K PARM ARE CASE-SENSITIVE.
The keymask may contain numbers, uppercase letters, and any of the
other printable characters on the keyboard.
There is no way to tell FDATE to accept "special" keypresses such as
function keys, ALT or CONTROL keys, arrow keys, etc.
If the keymask contains an uppercase letter (e.g. "A"), and the user
presses the corresponding unshifted letter (e.g. "a"), then the
keypress will be accepted and the uppercase letter will be returned.
The keymask may contain the following lowercase letters, which have
special meanings:
x represents the ESCAPE key
e represents the ENTER (RETURN) key
z [a place-holder character]
Lowercase "z" will be ignored when FDATE decides which
keypresses are acceptable. Its presence in the keymask will
affect the positions of other characters in the keymask, and
hence the ERRORLEVEL that FDATE returns when the user presses
an acceptable key. (For the uses of "z", see "GetK Results
also in ERRORLEVEL" and "Modifying the Keymask", below.)
All other lowercase letters are reserved for possible future use. In
the current release of FDATE, they are treated like lowercase "z".
EXAMPLE: If a keymask of "/kXx" was specified, then if the user
pressed the (shifted or unshifted) "X" key, then uppercase
"X" would be returned. If he pressed the ESCAPE key, then
lowercase "x" would be returned.
GetK Results also in ERRORLEVEL
When the GETK function returns a key, it sets the DOS errorlevel to a
value corresponding to the position of that key in the keymask. For
example, with keymask of "/kABx", if the user presses:
"A": value returned will be "A", errorlevel will be 1
"B": value returned will be "B", errorlevel will be 2
ESCAPE: value returned will be "x", errorlevel will be 3
If the user presses CONTROL+BREAK, FDATE will abort and return
errorlevel 255.
Here is an example batch file:
==================================================================
@echo off
cls
echo Demonstration of FDATE's GETK (get keypress) function
echo Press CONTROL+BREAK to end
:top
echo.
fdate /fGetK /P"You pressed: " /Q"Press a key: " /K"12ABxe "
if errorlevel 1 if not errorlevel 2 echo errorlevel : 1
if errorlevel 2 if not errorlevel 3 echo errorlevel : 2
if errorlevel 3 if not errorlevel 4 echo errorlevel : 3
if errorlevel 4 if not errorlevel 5 echo errorlevel : 4
if errorlevel 5 if not errorlevel 6 echo errorlevel : 5
if errorlevel 6 if not errorlevel 7 echo errorlevel : 6
if errorlevel 7 if not errorlevel 8 echo errorlevel : 7
if errorlevel 255 echo ERRORLEVEL 255
if errorlevel 255 goto endit
goto top
:endit
==================================================================
Note that the keymask may contain blanks if the keymask is enclosed in
quotes (as in this example batch file). But remember that Fdate
eliminates redundant spaces when obtaining its parameter input, so you
should never include more than one blank in your keymask.
Modifying the Keymask
It it is often necessary to make program modifications during the life
of a batch file. If you are using the GETK function and testing the
errorlevel rather than the environment, then the insertion or deletion
of characters into the existing keymask will change the errorlevels
returned by the following characters in the keymask. This will force
you to re-write the errorlevel tests, which may be a big job if the
keymask is long.
Here are some tips on how to avoid this work:
When ADDING a character to the keymask, always add it a the END
of the keymask.
When DELETING a character from the keymask, do not actually
delete it. Instead, replace it by a lowercase "z".
Displaying a User Prompt With GETK
The /Q (user prompt) parameter is especially handy when used in
conjunction with the GETK function. If the /Q prompt-string parameter
is specified (as in the example batch file, above), then the prompt
string is displayed, but a NEWLINE is not written to the screen before
waiting for the user's keypress.
For a program that provides more sophisticated "get key" functions for
batch files, I recommend Bob Stephan's shareware program GET, which is
described elsewhere in this documentation.
SUBSTR (SUBSTRING) FUNCTION
===============================
substr
This function returns a substring of the string supplied in the /Q
parm, starting in the column supplied in the /A parm, for a length
supplied in the /B parm.
The start column specified in the /A parm may be a negative number; if
it is, then the start column is calculated from the end of the string
rather than from the beginning. This feature makes it easy to extract
the rightmost characters of a string.
Specifically, when the ParmA is negative, the start position
is calculated using the following formula:
StartColumn = length(ParmQ) + 1 + ParmA
Example: Fdate /Fsubstr /A-2 /Qabcd
StartColumn = length(ParmQ) + 1 + ParmA
StartColumn = 4 + 1 + (-2) = 3
If /Q is omitted, Fdate reports an error.
If /A is zero, Fdate reports an error.
If /A is omitted, it defaults to 1 (that is, the start of the string).
If /A is negative, and longer than the length of the string, then the
start column is 1 (the start of the string)
If /B (length) is so great that it exceed the length of the /Q input
string, then only the remainder of the string is returned.
If /B is zero, Fdate returns a null string.
If /B is omitted, it defaults to 999.
EXAMPLES:
Fdate /Fsubstr /A7 /B2 /Q"STEVE FERG" ===> "FE"
Fdate /Fsubstr /A7 /Q"STEVE FERG" ===> "FERG"
Fdate /Fsubstr /B5 /Q"STEVE FERG" ===> "STEVE"
EXAMPLES using a negative start position:
Fdate /Fsubstr /a-6 /B3 /Q"1994 Jun 03" ===> "Jun
rem extract the rightmost 6 characters of a string
Fdate /Fsubstr /a-6 /Q"1994 Jun 03" ===> "Jun 03"
REMEMBER that Fdate eliminates redundant spaces when obtaining its
parameter input:
Fdate /Fsubstr /A7 /Q"STEVE FERG" ===> "FERG"
Fdate /Fsubstr /A7 /Q"STEVE FERG" ===> "FERG"
Fdate /Fsubstr /A7 /Q"STEVE FERG" ===> "FERG"
LEN (LENGTH) FUNCTION
=====================
len Produces a number that is the length of the string on the /Q
parm.
UPPER FUNCTION
===============
upper Produces the string on the /Q parm, converted to upper case.
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)
------------------------------------------------------------------
ddmmccyy 02081993
ddmmyy 020893
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/93
dd-mm-yy 02-08-93
dd.mm.yy 02.08.93 British-style dates
zd/zm/yy 2/8/93 no leading zeros in day or month
zd-zm-yy 2-8-93 no leading zeros in day or month
zd.zm.yy 2.8.93 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
xxx 2CP (...Dec 25, 1992)
This format represents dates for the years 1990-2024 in 3
characters of "extended hex" ("XX") notation. For more on XX
notation, see the discussion of the #2XX function.
The first character is the XX representation of the number of
years since 1990 (1990 = 0, 1991 = 1, etc.). If you attempt to
output a date outside of the 1990-2024 range in XXX format, Fdate
will report an error (i.e. return "ERROR" and errorlevel of 1).
The second and third characters contain the XX representation of
the month-number and day-of-month-number, respectively.
EXAMPLE: "1993 Feb 1" is represented as "321"
EXAMPLE: "2000 Dec 25" is represented as "ACP".
-----------------------------------------------------------------------
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,
although not the most convenient, 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 inexpensive and very powerful and flexible) and PC
Magazine's STRINGS (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 March 14, 1994, the current version of GET is 2.6. On
CompuServe, use IBMFF to look for GET25.ZIP (which contains version
2.5 and the full documentation file) and GET26u.ZIP (the version 2.6
update of GET, which contains version 2.6 of GET, but not the full
documentation). Look in CIS:IBMSYS, Library 1, 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, QuarterDeck, 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 in the "parent" 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
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 RUNNING UNDER MICROSOFT WINDOWS
=======================================
Starting with FDATE version 8.4 -- thanks to a Turbo Pascal routine from
the Turbo Professional library (see below) provided by Kim Kokkonen of
TurboPower Software -- FDATE's /V parameter works even in a Windows DOS
box, assuming you have enough environment space available.
Starting with Windows 3.1, Windows reads the SHELL= statement in your
CONFIG.SYS file and allocates the same amount of environment space to a DOS
window that you specify there. I've found that using the SHELL= statement
to set the environment size to 512 bytes is adequate for all of my needs.
If you're running Windows 3.0, or earlier, you should upgrade immediately!
Until then, always start Windows from a batch file that contains the
following line, executed BEFORE you start Windows:
SET DUMMY=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
This will reserve a chunk of environment space that will be copied into the
environment in the Windows DOS box. Then, as one of the first statements
in any batch file that you run under Windows, put
SET DUMMY=
This will free up the environment space used by all those "X"s. For a good
treatment of running DOS apps under Windows, including a discussion of the
environment, I recommend Brian Livingston's WINDOWS 3.1 SECRETS (Ch. 7).
Turbo Professional: "Highly Recommended"
If you do serious Turbo Pascal programming, you should have Turbo
Professional or Object Professional library. Turbo Professional is a
library of about 600 routines to do all sorts of useful stuff in Turbo
Pascal programs, including:
CRT unit emulation, with many added features
Popup windows, virtual screens, and pulldown menu systems.
Full screen data entry with formatting and data validation.
Complete mouse support, keyboard macros, runtime error recovery.
A context sensitive popup help unit.
Units for picking from lists of items, including filenames.
Easy and reliable ways to make your program memory resident.
Interrupt service routine handlers, extended & expanded memory access.
BCD arithmetic, including transcendental functions & the Form routine
Sorting and searching.
Extensive string manipulation & strings longer than 255 characters.
Arrays larger than 64K (in RAM, EMS, or paged to disk)
For more information, call TurboPower at 1-800-333-4160 (9-5 Mountain
time), send CompuServe mail to 76004,2611, or visit the CompuServe
TurboPower forum in PCVENB section 6.
/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.
Note, however, that this behavior has not been tested
with FDATE 8.4's new environment-handling routines.
--------------------------------------------------------------
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 GET with FDATE, to put FDATE output into 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 a batch file with FDATE, to put FDATE output 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
:07 Get user input
:==================================================================
@echo off
cls
echo Enter a date in mm-dd-ccyy format for validation
:: get user input
fdate /fget /vUserDate1
:: validate user input using /Fv (validate function)
fdate /fv /A%UserDate1% >nul
if errorlevel 1 echo Invalid date: %UserDate1%
if errorlevel 1 goto endit
:: put your batch file processing here ...
echo Processing date: %UserDate1%
:endit
:: cleanup
set UserDate1=
:08 Get a user menu selection
:==================================================================
@echo off
:start
cls
echo =================================================
echo MAKE A MENU SELECTION
echo =================================================
echo A menu item A
echo B menu item B
echo.
echo X exit from this program
echo.
echo =================================================
:: get user input in upper case
FDATE /fgetU /q"Press the letter of your choice, then ENTER > " /vchoice
echo.
if (%choice%)==(A) goto Choice_%choice%
if (%choice%)==(B) goto Choice_%choice%
if (%choice%)==(X) goto endit
echo Your choice was not valid: [%choice%] Please try again.
pause
goto Start
:CHOICE_A
echo Put processing for choice %choice% here
pause
goto Start
:CHOICE_B
echo Put processing for choice %choice% here
pause
goto Start
:endit
set choice=
cls
: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).
FORATIM2.BAT, which occurs in the next example, is an improvement of this
batch file. FORATIM2.BAT uses the /Fget function, which first appeared in
Fdate 8.3, to get user input from the terminal, rather than requiring all
parameters to be entered at the command line as FORATIME.BAT does.
@echo off
cls
:: ------------------------------------------------------
:: FORATIME.BAT batch file
::
:: FUNCTION
:: Calculate the elapsed time (in days and minutes)
:: between some "begin" date/time and some "end" date/time
::
:: USAGE
:: This batch file requires 4 command-line parameters
::
:: BegDate BegTime EndDate EndTime
::
:: Dates must include full 4-digit for year: mm-dd-ccyy
:: Times must be in 24-hour format: hh:mm
::
:: EXAMPLE
:: To calculate the elapsed time between
:: February 28, 1993 @ 8:11 pm and
:: March 2, 1993 @ 9:15 am
:: (note that 8:11 pm is 20:11 in 24-hour time format)
::
:: enter at the DOS prompt:
::
:: FORATIME 2-28-1993 20:11 3-2-1993 9:15
::
:: ------------------------------------------------------
:
set BEGdate=%1
set BEGtime=%2
set ENDdate=%3
set ENDtime=%4
ECHO Starting FORATIME calculations.
ECHO BEGIN date/time parms are: %1 %2
ECHO END date/time parms are: %3 %4
ECHO.
ECHO Validating BEGIN date/time parameters...
fdate /fv /A%BEGdate% /T%BEGtime% >nul
if errorlevel 1 goto endit
:: get absolute minute of start date/time.
fdate /ff /ominute# /A%BEGdate% /T%BEGtime% /VABStime1
if errorlevel 1 goto endit
fdate /ff /ofull /A%BEGdate% /T%BEGtime% /Vfull1
ECHO Validating END date/time parameters...
fdate /fv /A%ENDdate% /T%ENDtime% >nul
if errorlevel 1 goto endit
:: get absolute minute of end date/time.
fdate /ff /ominute# /A%ENDdate% /T%ENDtime% /VABStime2
if errorlevel 1 goto endit
fdate /ff /ofull /A%ENDdate% /T%ENDtime% /Vfull2
ECHO Calculating elapsed time...
:: calculate the difference between ABStime1 and ABStime2
fdate /f#dif /A%ABStime1% /B%ABStime2% /VMinutes
:: calculate the number of hours in it took
fdate /f#Idiv /A%minutes% /B60 /VHours
:: calculate the number of extra minutes it took
fdate /f#mod /A%minutes% /B60 /VMins
echo.
echo Between %full1%
echo and %full2%
echo.
echo Elapsed time was: %hours% hours and %mins% minutes
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 Elapsed time was: %day1% day(s) %hour1% hour(s) and %min2%
minute(s).
echo.
echo.
::: 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 FORATIM2.BAT
:==================================================================
FORATIM2.BAT, is the same as FORATIME.BAT in the previous example, except
that it uses the /Fget function, which first appeared in Fdate 8.3, to get
user input from the terminal, rather than requiring all parameters to be
entered at the command line.
@echo off
cls
:: ------------------------------------------------------
:: FORATIM2.BAT batch file
::
:: FUNCTION
:: Calculate the elapsed time (in days and minutes)
:: between some "begin" date/time and some "end" date/time
::
:: ------------------------------------------------------
ECHO --------------------------------------------------------------
ECHO Calculate elapsed time between two date/times
ECHO --------------------------------------------------------------
:BegDate
Fdate /Fget /VBEGdate /Q"Enter BEGIN DATE (mm-dd-ccyy): "
:BegTime
Fdate /Fget /VBEGtime /Q"Enter BEGIN TIME (hh:mm).....: "
:: validate date & time
fdate /fv /A%BEGdate% /T%BEGtime% >nul
if errorlevel 1 echo Invalid date/time
if errorlevel 1 goto BegDate
:: get absolute minute of start date/time.
fdate /ff /ominute# /A%BEGdate% /T%BEGtime% /VABStime1
if errorlevel 1 goto BegTime
fdate /ff /ofull /A%BEGdate% /T%BEGtime% /Vfull1
:
echo.
:EndDate
Fdate /Fget /VENDdate /Q"Enter END.. DATE (mm-dd-ccyy): "
:EndTime
Fdate /Fget /VENDtime /Q"Enter END.. TIME (hh:mm).....: "
:: validate date & time
fdate /fv /A%ENDdate% /T%ENDtime% >nul
if errorlevel 1 echo Invalid date/time
if errorlevel 1 goto EndDate
:: get absolute minute of end date/time.
fdate /ff /ominute# /A%ENDdate% /T%ENDtime% /VABStime2
if errorlevel 1 goto EndTime
fdate /ff /ofull /A%ENDdate% /T%ENDtime% /Vfull2
echo.
ECHO Calculating elapsed time...
:: calculate the difference between ABStime1 and ABStime2
fdate /f#dif /A%ABStime1% /B%ABStime2% /VMinutes
:: calculate the number of hours in it took
fdate /f#Idiv /A%minutes% /B60 /VHours
:: calculate the number of extra minutes it took
fdate /f#mod /A%minutes% /B60 /VMins
echo.
echo Between %full1%
echo and %full2%
echo.
echo Elapsed time was:
echo %hours% hours and %mins% minutes
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
echo %day1% day(s) %hour1% hour(s) and %min2% minute(s).
echo.
echo.
:
:: 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
:14 Time the execution of a piece of software
:==================================================================
COMMENT
This example was developed 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=
:31 Compare two files' date/time using COMPARE-FUNCTION ERRORLEVELS
:==================================================================
COMMENT
There are many ways to check errorlevels. This example shows
several of them.
@echo off
cls
SET F1=FDATE.BAT
SET F2=FDATE.EXE
fdate /FTcomp /If /A%f1% /B%F2% /P"%f1% is " /S" %f2%"
if errorlevel 101 if not errorlevel 103 echo %f1% is LT/EQ %f2%
if errorlevel 102 echo %f1% is GT/EQ %f2%
if errorlevel 101 if not errorlevel 102 echo %f1% is older than %f2%
if errorlevel 102 if not errorlevel 103 echo %f1% is same age as %f2%
if errorlevel 103 if not errorlevel 104 echo %f1% is younger than %f2%
if errorlevel 101 if not errorlevel 103 echo %f1% at least as old as %f2%
if errorlevel 102 echo %f1% is no older than %f2%
if errorlevel 101 if not errorlevel 102 echo errorlevel is 101
if errorlevel 102 if not errorlevel 103 echo errorlevel is 102
if errorlevel 103 if not errorlevel 104 echo errorlevel is 103
SET F1=
SET F2=
:endit
: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 parameters 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 : "
:50 Represent a date in 3 bytes of "extended hex" notation
:==================================================================
rem produce today's date as 3 bytes
fdate /ff /oxxx
rem produce yesterday's date in xxx format
fdate /fsub /N1 /oxxx
: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 how to use Fdate's #2XX function 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
You can also use Fdate's "XXX" output format to represent dates between
1990 and 2024 in 3 bytes of extended hex notation.
------------------------------------------------------------------
:end-doc
REM OBTAIN 1-CHARACTER REPRESENTATION FOR THE MONTH
Fdate /ff /Omm /Vmm
Fdate /f#2xx /A%mm% /Vmm
echo XX representation of this month's number is %mm%
REM OBTAIN 1-CHARACTER REPRESENTATION FOR THE DAY
Fdate /ff /Odd /Vdd
Fdate /f#2xx /A%dd% /Vdd
echo XX representation of today's day of the month is %dd%
REM CONCATENATE THEM TO THE 2-CHARACTER REPRESENTATION FOR THE YEAR
Fdate /Ff /Oyy /S%mm%%dd% /Vdate
echo XX representation of today's full date is %date%
REM CLEANUP
set mm=
set dd=
set date=
: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
:58 Convert numbers to "extended hex" (XX) format
:==================================================================
@echo off
cls
SET decnum=0
:top
if (%decnum%)==(37) goto endit
fdate /f#2xx /A%decnum% /P"XX representation of %decnum% is "
fdate /f#add /A%decnum% /b1 /Vdecnum
goto top
: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=
:62 Run specific software, depending on the day of the week
:==================================================================
COMMENT
This is a very common use for Fdate. I use it to load an alarm-clock TSR
(Terminate and Stay Resident, "memory resident", program) that beeps at me
(at different times on different days of the week) to remind me that it is
time to attend a meeting that is regularly 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. If you want stuff (e.g. a backup job) to
be run only once (the first time you boot up) on a given day of the week,
then:
(1) copy the code from DO-ONCE (the previous example) into your
AUTOEXEC.BAT file, then
(2) copy this code into the body of the DO-ONCE code that you copied into
AUTOEXEC.BAT in the last step. 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 should 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.
Note that the string comparison is case sensitive.
==================================================================
:: get 3-character day-of-week name and put it in DOW e-var
FDATE /ff /oDOW3 /vDOW
if (%DOW%)==(Mon) alarmTSR.exe 10:30 Time for Monday staff meeting
if (%DOW%)==(Fri) echo Running Friday backup. Please wait...
if (%DOW%)==(Fri) CALL BACKUP C:
if (%DOW%)==(Fri) CALL BACKUP D:
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]
:66 Change a filename to contain today's date in first 3 bytes
:==================================================================
FDATE /Ff /Oxxx /vXXX
ren BACKUP.LOG %XXX%-BACK.LOG
SET XXX=
:67 Change a file's name to a name that contains today's date
:==================================================================
FDATE /Ff /At /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=
:71 Extract the rightmost n characters of a string
:===============================================================
rem extract the rightmost 6 characters of a string
FDATE /Fsubstr /a-6 /Q"1994 Jun 03" ===> "Jun 03"
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) and demonstration batch files and doc files (HOLIDAYS.BAT,
HOLIFEDS.BAT, HOLIFEDS.DOC) 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.
I distribute all versions of FDATE in a files called FDATE.ZIP, rather than
embedding information about the version in the file name. I think doing
this helps newer versions of FDATE to force older versions out of
circulation. To give a BBS user information about the version, I always
identify the version of FDATE in the 1-line file description that most BBSs
support.
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]
HOLIDAYS.BAT
HOLIFEDS.BAT and HOLIFEDS.DOC
RECENT 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.
7.0a Nov 14, 1992
Added #mod function
Major reformatting of documentation to make it more user-friendly
7.1a Apr 15, 1993
Added German language support. Thanks for the request, and the
necessary information, from Patrick Schmucki, via the Active-Net
BBS in Rapperswil, Switzerland.
8.0 July, 1993
Added "V" (validate) and "m" (month addition/subtraction) functions
Added math functions: #mult #div #idiv
Added /T (time) parameter
Added FORATIME.BAT example, which Walter Ledge (assistant sysop of
CompuServe's CRFORUM) and I developed. A big thanks to Walt for
his feedback and help.
8.1 July 27, 1993 BUG FIX
An error-trapping routine that was added to version 7.9 contained a
bug that caused Fdate's numeric math functions (#add, #dif, #mult,
#div, #idiv, #mod, #comp, etc.) to return incorrect results.
8.2 August, 1993
Removed FILEDATE.BAT from the distribution .ZIP file.
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.
8.3a Feb 24, 1994
* Added the following string-handling functions:
get (get user input)
getu (get uppercase user input)
upper (uppercase a string)
len (length of a string)
substr (substring)
* Added /F#2xx (convert number to extended hex format) function.
Deleted SETXX.BAT, which has been made obsolete with the addition
of this new function. Modified second example of storing a 4-digit
date to use #2xx instead of SETXX.BAT.
* Added output formats "ddmmccyy" and "ddmmyy" at the request of
several users.
* Added output format "xxx" after several requests for advice on how
to represent a large range of dates in a minimum number of bytes
(usually for constructing filenames from today's date).
* At the request of several users, enhanced the "compare" functions
(comp, tcomp, #comp) so they set distinctive errorlevels for their
different results. See the table of contents ("COMPARE-FUNCTION
ERRORLEVELS") and EXAMPLES.
To discussion of /Fv parameter, added note about almost always
redirecting output to NUL when using /Fv.
Revised FORATIME.BAT example batch file to make error-correction a
bit more robust and to add better documentation on how to use it.
Added example batch files to use new functions, especially
FORATIM2.BAT which uses new "get" function
Removed FDATEX.BAT demonstration batch file from distribution
package, to reduce its size. The examples in this DOC file should
make the examples in FDATEX.BAT unnecessary
8.4a March 20, 1994
* Added GETK (get keypress) function
* Added ability to use /V when running in a Windows DOS box, thanks
to a Turbo Pascal routine from the Turbo Professional library
provided by Kim Kokkonen of TurboPower Software.
Fixed a bug in which the prompt string (/Q) for the GET and GETU
functions was being written to redirectable output (StdOut). The
prompt string is now written directly to the screen, and will not
appear in FDATE's output when the output is redirected to a file.
Removed ALARM.BAT, ALARM.DOC, TIC.BAT and TIC.DOC from distribution
package. They were too esoteric to be generally helpful.
Added FILE_ID.DIZ and DESC.SDI to distribution package.
Corrected algorithm for Mardi Gras in HOLIDAYS.BAT. Modified
HOLIDAYS.BAT and HOLIFEDS.BAT to make them more interactive, using
FDATE's new abilities to get user input.
* Started ZIPing FDATE.ZIP with PKZIP 2.04g rather than version 1.1