Date variables in Batch programming

Custom / CUSTOM
March 4, 2009 at 00:03:59
Specs: Microsoft Windows Vista Ultimate, 3.2 GHz / 3069 MB
Hi, guys... I have a certain problem, but to be more inlighting i will post my code and explain the problem beyond.

/ / 
/subject:"my subject  %date% and %????%" /body:"my body %date% and after %?????%" 

the %????% is what i am looking for!!!!

Into this code i call an application, the CLmailer, which sends the email... It sends the email including the subject, body, to etc. into the subject and the body, except of my comments, i want to be sent extra info the current date and the date 5 days after the current. I have achieved only the current date, by the %date% command, but i cannot figure out the command of the date 5 days after the current... I'm looking forward some discussion and solves on the issue!

See More: Date variables in Batch programming

Report •

March 4, 2009 at 00:29:51
Date manipulation in batch scripting is not the easiest thing to code. Combining a small bit of VBS helps reduce the difficulty so:

Save the following code as EVALDATE.VBS in your path

Code begins......

Wscript.echo eval(WScript.Arguments(0))

Code ends....

Include the following code in your batch script

:: Code begins....

for /f "delims==" %%A in ('evaldate date+5') do (
     set newdate=%%A

:: Code ends....

The variable %newdate% should contain the date 5-days hence.

Good luck - please post back with your result.

Edit: Sorry, I should have mentioned that the above has been tested in Win.XP only. It may or may not work in Vista.

Report •

March 4, 2009 at 03:00:52
First of all, i thank u Valerie for your reply...
Now on our issue, when i run the batch file it echoes me the "after 5 days" date correctly and then it sends the email, but when i open the email it doesn't post me the "after 5 days date" even though i call the variable %newdate% in the subject.
It posts me only the current date and at the space it should post the newdate it posts nothing. I test it at vista and at xp but it's the same... It's like it doesn't save the "after 5 days" date in the newdate variable which i call in the code beyond. Does any idea come upon you...?

Report •

March 4, 2009 at 07:48:08
it echoes me the "after 5 days"
How? In a popup message box?

Report •

Related Solutions

March 4, 2009 at 07:53:50
Yes... when the for loop is executed it pops up a window with the "after 5 days" result. Although it's correct it's useless, i want to save it onto a variable which i will call later on the script.
I believe that the EVALDATE.VBS is responsible of the pop up window. Any suggestions of how to store the result of the pop up window onto a variable?

Report •

March 4, 2009 at 08:09:00
for /f "delims==" %%A in ('cscript evaldate.vbs date+5') do (

Report •

March 4, 2009 at 08:19:32
Se euxaristw polu file mou... Eurika
Many thanks my friend, that was the answer. Hope to be useful to the forum some next time like you and Valerie were to me...

Report •

March 4, 2009 at 08:31:01
Hi Razopr2.3,

why "delims==" ?

If at first you don't succeed, you're about average.


Report •

March 4, 2009 at 08:42:17
Mechanix2Go: why "delims==" ?
'Cause that's what the original line had.

Report •

March 4, 2009 at 08:46:20
The script works fine for me... What is delims? Could a different solution offer something better...?

Report •

Ask Question