I need some pointer crafting an MS-DOS batch "function" to advance the system calendar N number of days from the current one. Is there a more machine-friendly command, or am I stuck with DATE
and some Franken-hack parsing of it?
2 Answers
On one of my favorite batch sites on the net Rob van der Woude's Scripting Pages you can find in the examples section a script called DateAdd.bat. It will calculate and print a new date based on a given date and offset.
It should be fairly easy to change the script to your needs or use it along with your own script. Get back to us if you need further help with that.

- 24,478
- 5
- 49
- 58
-
Ha! 220 LOCs to add dates! :D – Dr. belisarius Nov 03 '10 at 00:38
-
Not so easy converting NT4 script down to MS-DOS :-) but it's a good site, I'll give you that much. – paxdiablo Nov 03 '10 at 00:38
-
Thanks. This looks very promising. – Santa Nov 03 '10 at 01:02
-
@paxdiablo: people talking about MS-DOS, but actually meaning the NT4 and above command line are very common at this site. – Frank Bollack Nov 03 '10 at 08:07
-
@belisarius: Indeed, but it looks very clean and easy readable. I couldn't imagine it can be done in less than 500 LOC. – Frank Bollack Nov 03 '10 at 08:13
-
@Frank I wasn't trying to criticize. I've almost forgotten the pain of programming robust routines in DOS (Been there, done that, forgot for sanity :) – Dr. belisarius Nov 03 '10 at 11:46
-
Unfortunately, I am stuck with it for the moment. Woe is me :( – Santa Nov 03 '10 at 15:59
-
@Santa: So you can either update your questions and show how far you got or create a new question referring to this one. Where did you get stuck? – Frank Bollack Nov 03 '10 at 16:02
-
@Frank. I did not. I used your script and used `DATE
` instead of printing the new date (among other minor modifications) and I got what I wanted. Thanks. – Santa Nov 03 '10 at 16:14 -
@Frank Ah, when I said, "I am stuck with it," I meant with DOS scripting instead of, say, Python. =( – Santa Nov 03 '10 at 16:14
If you're truly using MS-DOS
rather than the more advanced cmd.exe
, your options are very limited since the variable manipulation was pretty bad.
I do remember needing something similar in a previous life. From memory, rather than trying to screw around with date calculations, we simply ran a loop (one iteration for each day) and, inside the loop, set the time to 23:59 then wait for five seconds or so. Unfortunately, I think that pre-dated ping
so we couldn't even use the sleep trick - we had to run a lengthy goto
loop to be certain.
That way, DOS itself figured out whether "tomorrow" was the 31st of September or 1st of October.
In the end, it became too much trouble so I would suggest you do what we finished up doing. Grab yourself a copy of Turbo C from Borland's (or InPrise or Enchilada or whatever they're called nowadays - they'll always be Borland to me) museum site and write a quick little C program to do it for you .
-
"Some" years ago :) I wrote in assembler a command.com "wrapper" (although the word wasn't in use yet) to be able to implement this kind of tricks (the sleep one, for example). Ended up migrating to Turbo-C after the monster became too big. Bow : http://www.amazon.com/Advanced-S-DOS-Programming-Microsoft-Programmers/dp/0914845772/ref=pd_sim_b_4 – Dr. belisarius Nov 03 '10 at 00:35