Printer Version Table of Contents Project Home Page
.INTRODUCTION: 4 - The 3-Minute Introduction to Fdate
This is a "quick start" introduction to using Fdate.


Fdate is a utility for doing date formatting and date arithmetic in DOS batch files. At least, that was its original purpose. Over the years, functions were added to Fdate to support activities that people often need to do in conjunction with working with dates.

To help you get started using Fdate, I've created this short introduction which shows how to use Fdate to do the things most users want to do. When you've finished, you may still have a question: "Can I do such-and- such with Fdate?" If it involves dates, it probably CAN be done with Fdate, although tricky things are of course tricky to do, even with Fdate. A good next step would be to look at the list of examples. With luck, you will find an example that shows Fdate doing just what you want to do. To understand how Fdate is working in a particular example, look up the parameters used in the example. see OVERVIEW Examples


By far the most popular use of Fdate is to put today's date-- in a particular format-- into an environment variable. Once this has been done, the environment variable can be used and manipulated in many ways in a batch file. Here are a few short exercises that will help you to learn how to use Fdate's most basic features to do that.

1. At the DOS prompt, type:

This will show you Fdate's HELP screens. Press ENTER to page through the HELP screens.

The information on these HELP screens is very dense. It won't teach you how to use Fdate, but it is useful for jogging your memory as you become familiar with Fdate's various features.

2. At the DOS prompt, type:

       FDATE /Ff
I've used lowercase "f" here to distinguish the value of the parameter from the parameter-letter itself, but it really doesn't matter whether the parameter or its value is in upper or lower case. Except for the /K parameter (one of Fdate's advanced features), Fdate's parameters are not case sensitive.

Here, the value of the "/F" (function) parameter is "f" (format a date). The "/Ff" parameter tells Fdate that the function you want it to perform is to format a date. Since the default date is "today", this command will cause Fdate to display today's date on your screen in Fdate's default output format.

3. At the DOS prompt, type:

       FDATE /Ff /P"Today is "
This command is just like the one in the previous example, except that we've specified the "prefix parameter" (/P), which tells Fdate to add a string to the beginning of its output. (There is also a "suffix parameter" that tells Fdate to add a string to the end of its output.) Note that the value of the /P parameter is enclosed in quotes. (Either single quotes or double quotes will work.) We've had to enclose the value in quotes because it contains embedded blanks (one blank after the word "today" and another after the word "is").

4. At the DOS prompt, type:

       FDATE /Ff /Occyymmdd
(Or you can put the same statement in a batch file.)

Here, you are telling Fdate to put out today's date in a specific format. On the "output format" parm (/O) you are specifying that you want the day in "ccyymmdd" format: two digits each for century, year- within-century, month, day-of-month.

Note that the /O parm is a predefined, fixed, format. Fdate supports many such pre-defined output formats. If you want more flexibility, then you can "roll your own" date format using the /C (custom output) parameter.

5. At the DOS prompt, type:

       FDATE /Ff /C"$Today is $N $d, $Y"
Here, you are telling Fdate to put out a string that you have formatted. The /C parm tells Fdate that the output will be a customized format. The string after the /C is enclosed in quotes, because it contains blanks. The first character inside the string is a $ -- this tells Fdate that you will be using the $ as the escape character. The symbols $M, $d, and $Y have special meaning. (Note that, unlike most of Fdate's parameters, these special symbols ARE case-sensitive.) For more information, see PARAMETER /C - Custom Output Date Formats

6. At the DOS prompt, type:

      FDATE /Ff /Occyymmdd /p"@set date1="  >junk.bat
(Or you can put the same statement in a batch file.)

Here, you are telling Fdate to put out today's date in "ccyymmdd" format. Because you are specifying the redirection symbol (>) and a batch file name, Fdate's output is being redirected to the batch file. You can look at the batch file by using the DOS "type" command:

Now you can run the batch file by typing

at the DOS command prompt.

This will cause JUNK.BAT to run and to put today's date in the DATE1 environment variable. If you type "SET" at the DOS prompt, and if today is February 1, 1995, you will see as the last line of the SET output:

7. Use your favorite text editor to create a batch file called TEST.BAT. In TEST.BAT, put the following lines:

       @echo off
       FDATE /Ff /p"@set date1="  >junk.bat
       call  junk.bat
       del   junk.bat
       echo Today's date is: %date1%
       set  date1=
Note that in this example we have not specified an output format at all, so Fdate will use its default format.

Here is the same batch file, with some commentary:

       @echo off                *** turn ECHO off, so the batch file executes quietly
       FDATE /Ff /p"@set date1=" >junk.bat   *** you know what this does
       call  junk.bat           *** call junk.bat to set the date1 environment variable
       del   junk.bat           *** cleanup -- delete junk.bat
       echo Today's date is: %date1%     *** use the environment variable
       set  date1=              *** cleanup -- delete date1
8. At this point, you know everything you need to know to put today's date into an environment variable, which you can then use for whatever you want. As the last step in this introduction, here's an example in which you are copying a file (BACKUP.LOG, which is put out by a backup program) to a file whose name contains today's date.

            FDATE /Ff /Occyymmdd /Vdate1
            copy BACKUP.LOG  %date1%.LOG


Now that you know the basics, you may have everything you need to know in order to use FDATE to satisfy your basic date-handling needs. If you need more information, or are feeling adventurous, your next step should be to explore the Fdate documentation, which discusses many more features of FDATE.

One of the most useful parts of the documentation is the list of examples. Browse through the titles of the examples, to get a feel for what is there. see OVERVIEW Examples

Then look at the examples themselves. Many are quite elaborate (which is natural, since they are there to show you how to do Hard Stuff).

Most of the examples are self-contained and ready-to-run -- if you copy the text of the example into a batch file, the example code will run and do what the title says it will do. I suggest you try one or two of the examples that seem most interesting to you.

After the examples, the most useful parts of the Fdate documentation are the sections documenting Fdate's various functions (the functions that you can specify on the function parm, /F) and its various output formats. I suggest you scan those sections, just to get a quick feel for what's available to you.

Good Luck!

Steve Ferg