Page 1 of 1

Week number to Private data

Posted: Mon Jul 16, 2018 1:33 pm
by Terkelsen
I have found this simple command, that will return the week number.

Code: Select all

For /F %I In ('PowerShell Get-Date -UFormat %V') Do @Echo(%I
Is there any way to write this information into the Private Data of a file?

Re: Week number to Private data

Posted: Mon Jul 16, 2018 11:35 pm
by dkelly
In script

Code: Select all

function getWeekNumber(d) {
    d.setDate(d.getDate() + 4 - (d.getDay()||7));
    var yearStart = new Date(d.getYear(),1,1);
    var weekNo = Math.ceil(( ( (d.getTime() - yearStart.getTime()) / 86400000) + 1)/7);
    return weekNo;
}

var weekNo = getWeekNumber(new Date());
job.setPrivateData("week", weekNo);

Re: Week number to Private data

Posted: Thu Jul 19, 2018 9:41 am
by Terkelsen
Thanks, Dwight

With a little help, I got this working in SwitchScripter :-)

Re: Week number to Private data

Posted: Wed Jul 25, 2018 10:22 am
by bens
Be aware that there are different definitions of "week number": one that is prevalent in the US, and one (recommended by the ISO) used more in Europe. A US week 32 could be an ISO week 31 or vice versa. This might not be important for your case, but don't let it surprise you.

Re: Week number to Private data

Posted: Tue Aug 14, 2018 3:55 pm
by Terkelsen
Thank you for pointing that out, bens, but I'm aware of that. According to the ISO standard week 01 is the first week of the year that contains a Thursday (or 4th January). I think that is exactly what Dwights script is calculating.