DosTips.com

A Forum all about DOS Batch
It is currently 06 May 2016 18:28

All times are UTC-06:00




Post new topic  Reply to topic  [ 18 posts ]  Go to page Previous 1 2
Author Message
PostPosted: 16 May 2011 17:03 
Offline
Expert

Joined: 22 Jan 2010 18:01
Posts: 1974
Location: Germany
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


Top
   
PostPosted: 17 May 2011 11:57 
Offline
Expert

Joined: 17 Oct 2009 08:30
Posts: 378
Location: Russia
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

:?


Top
   
PostPosted: 17 May 2011 12:53 
Offline
Expert

Joined: 22 Jan 2010 18:01
Posts: 1974
Location: Germany
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


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 18 posts ]  Go to page Previous 1 2

All times are UTC-06:00


Who is online

Users browsing this forum: Aacini, Bing [Bot], Compo, ShadowThief, Yahoo [Bot] and 3 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® Forum Software © phpBB Limited