Adding or subtracting days from current date

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
anand1773
Posts: 1
Joined: 06 Sep 2010 21:55

Adding or subtracting days from current date

#1 Post by anand1773 » 06 Sep 2010 22:16

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

jeb
Expert
Posts: 1058
Joined: 30 Aug 2007 08:05
Location: Germany, Bochum

Re: Adding or subtracting days from current date

#2 Post by jeb » 08 Sep 2010 03:41


ghostmachine4
Posts: 319
Joined: 12 May 2006 01:13

Re: Adding or subtracting days from current date

#3 Post by ghostmachine4 » 08 Sep 2010 06:01

here's the easier way without all maintaining all that batch date workarounds from jeb's link

download coreutils for windows, then use the date command

Code: Select all

c:\test> gnu_date.exe -d "1 year ago"
c:\test> gnu_date.exe -d "1 year"

Post Reply