# Adding or subtracting days from current date in batch script

**URL:** <https://community.unix.com/t/adding-or-subtracting-days-from-current-date-in-batch-script/272898>\
**Category:** Microsoft Windows\
**Created:** [September 7, 2010, 12:29am UTC](https://community.unix.com/t/adding-or-subtracting-days-from-current-date-in-batch-script/272898 "2010-09-07T00:29:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![anand1773](https://community.unix.com/letter_avatar/anand1773/32/6_449c533f586939b6e5f246632a46421f.png) [@anand1773](https://community.unix.com/u/anand1773)\
**Post date:** [September 7, 2010, 12:29am UTC](https://community.unix.com/t/adding-or-subtracting-days-from-current-date-in-batch-script/272898/1 "2010-09-07T00:29:45Z")

</div>

Hi,

I'm writing an batch file to create report

In the batch file iam passing two arguments:startdate and finishdate

Ex: startdate=07-sep-2009 finishdate=07-sep-2011

I need to have script that takes command line argument as input and gives me out currentdate last year and current date next year as mention above example.

currentdate-1 year & currentdate+ 1year

For example if I pass argument as 07-sep-2010 to batch script I should get ouput as startdate=07-sep-2009 finishdate=07-sep-2011.

Could any one please help?.

Regards,  
Anand

---

<div class="post-metadata">

**Author:** ![Tytalus](https://community.unix.com/user_avatar/community.unix.com/tytalus/32/87_2.png) [@Tytalus](https://community.unix.com/u/Tytalus)\
**Post date:** [September 7, 2010, 7:58am UTC](https://community.unix.com/t/adding-or-subtracting-days-from-current-date-in-batch-script/272898/2 "2010-09-07T07:58:04Z")

</div>

check the FAQ article [http://www.unix.com/answers-frequently-asked-questions/13785-yesterdays-date-date-arithmetic.html](http://www.unix.com/answers-frequently-asked-questions/13785-yesterdays-date-date-arithmetic.html)

You should find what you want ( and more 🙂 ) in there

---

<div class="post-metadata">

**Author:** ![Leo\_Gutierrez](https://community.unix.com/user_avatar/community.unix.com/leo_gutierrez/32/5319_2.png) [@Leo\_Gutierrez](https://community.unix.com/u/Leo_Gutierrez)\
**Post date:** [January 12, 2011, 2:38pm UTC](https://community.unix.com/t/adding-or-subtracting-days-from-current-date-in-batch-script/272898/3 "2011-01-12T14:38:21Z")

</div>

```nohighlight
@echo off
setlocal enabledelayedexpansion
if "%1" == "" (
	echo Error
	exit /b 1
)

for /f "tokens=1,2,3 delims=-" %%a in ("%1") do (
	set /a yearStart=%%c - 1
	set "startdate=%%a-%%b-!yearStart!"
	set /a yearFinish=!yearStart! + 2
	set "finishDate=%%a-%%b-!yearFinish!"
)
echo Start : !startdate!
echo Finish : !finishDate!

```

```nohighlight
C:\>code.bat 07-sep-2010
Start : 07-sep-2009
Finish : 07-sep-2011

C:\>

```
