Re: "universal" %DATE% parser
Posted: 16 May 2011 17:03
Well Dave, don't get me wrong -- this is a batch forum and I appreciate pure batch solutions. My objection was if you use JScript you should make as simple as you can. Normally I try to avoid those chimeras because they slow down your batch file enormously. If there is no (good) possibility with pure batch I prefer writing the whole thing in VBScript or C++.
How ever.
You could use functions in the JScript and then call one of them depending on an argument.
Regards
aGerman
How ever.
You could use functions in the JScript and then call one of them depending on an argument.
Code: Select all
@set @junk=0 /* The 1st 3 lines should not be changed
@echo off & set "@junk="
setlocal
cscript //nologo //e:jscript "%~f0" year
cscript //nologo //e:jscript "%~f0" month
cscript //nologo //e:jscript "%~f0" day
pause
goto :eof
*/
var d = new Date();
var arg = WScript.Arguments(0)
if (arg == "year") year();
else if (arg == "month") month();
else if (arg == "day") day();
else WScript.Quit(1);
function year() {
WScript.Echo(d.getFullYear());
}
function month() {
WScript.Echo(d.getMonth() + 1);
}
function day() {
WScript.Echo( d.getDate());
}
Regards
aGerman