Printer Version | Table of Contents | Project Home Page |
INTRODUCTION: WHAT IS 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.THE 3-MINUTE INTRODUCTION TO FDATE
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.FDATEThis will show you Fdate's HELP screens. Press ENTER to page through the HELP screens.
FDATE /FfI'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.
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").
FDATE /Ff /Occyymmdd(Or you can put the same statement in a batch file.)
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
FDATE /Ff /Occyymmdd /p"@set date1=" >junk.bat(Or you can put the same statement in a batch file.)
TYPE JUNK.BATNow you can run the batch file by typing
JUNK.BATat the DOS command prompt.
DATE1=199502017. 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.
@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 date18. 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
WHAT TO DO NEXT?
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.