Printer Version Table of Contents Project Home Page
.EXAMPLE.....: 30 Find the date 1 month, 3 months, 1 year from today
.CATEGORY....: examples
.DISCUSSION..:
This example uses Fdate's month-arithmetic function: /Fm.

The /N parm specifies the number of months that we want to add to the date specified on the /A parm. Note that we can specify a negative number on the /N parm, which will return a date which is the number of months BEFORE the date on the /A parm.

In the last example, we find the date one year after February 29, 2004, which is a leap year. Note that Fdate does NOT return February 29, 2005, which is a non-existent date.

.CODE........:
@ECHO OFF
echo.

set months=1
FDATE /Fm /At  /N%months%    /p"set date2=" > junk.bat
call junk.bat
del junk.bat
Echo %months% month(s) from today is %date2%

:: Show month arithmetic
set months=-1
FDATE /Fm /At  /N%months%    /p"set date2=" > junk.bat
call junk.bat
del junk.bat
Echo %months% month(s) from today is %date2%

echo.
set months=3
FDATE /Fm /At  /N%months%    /p"set date2=" > junk.bat
call junk.bat
del junk.bat
Echo %months% month(s) from today is %date2%

set months=12
FDATE /Fm /At  /N%months%    /p"set date2=" > junk.bat
call junk.bat
del junk.bat
Echo One year from today is %date2%


echo.
set date1=2004-02-29
set months=12
FDATE /Fm /A%date1% /Iccyy-mm-dd /N%months%    /p"set date2=" > junk.bat
call junk.bat
del junk.bat
Echo %months% month(s) from %date1% is %date2%

::cleanup
SET DATE1=
SET DATE2=