View unanswered posts | View active topics It is currently 20 Oct 2014 23:18



Post new topic Reply to topic  [ 18 posts ]  Go to page Previous  1, 2
"universal" %DATE% parser 
Author Message
Expert

Joined: 22 Jan 2010 18:01
Posts: 1800
Location: Germany
Post Re: "universal" %DATE% parser
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.
Code:
@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


16 May 2011 17:03
Profile
Expert

Joined: 17 Oct 2009 08:30
Posts: 378
Location: Russia
Post Re: "universal" %DATE% parser
aGerman wrote:
Sorry guys, but now I'm totally confused. On the right hand you use JScript-injection, on the left hand nobody has the idea to use it for getting the date directly

Image

:?


17 May 2011 11:57
Profile
Expert

Joined: 22 Jan 2010 18:01
Posts: 1800
Location: Germany
Post Re: "universal" %DATE% parser
OMG, you're right !k :oops: I forgot getMonth() returns 0 for january and 11 for december, so we have to add 1. I will edit the codes above...

Thanks
aGerman


17 May 2011 12:53
Profile
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 18 posts ]  Go to page Previous  1, 2


Who is online

Users browsing this forum: Bing [Bot], Google [Bot], Yahoo [Bot] and 8 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Forum style by Vjacheslav Trushkin for Free Forums/DivisionCore.