Week number to Private data

Post Reply
User avatar
Terkelsen
Advanced member
Posts: 297
Joined: Thu Sep 08, 2011 5:08 pm
Contact:

Week number to Private data

Post 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?
dkelly
TOP CONTRIBUTOR
Posts: 658
Joined: Mon Nov 29, 2010 8:45 pm
Location: Alpharetta GA USA
Contact:

Re: Week number to Private data

Post 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);
User avatar
Terkelsen
Advanced member
Posts: 297
Joined: Thu Sep 08, 2011 5:08 pm
Contact:

Re: Week number to Private data

Post by Terkelsen »

Thanks, Dwight

With a little help, I got this working in SwitchScripter :-)
bens
Advanced member
Posts: 252
Joined: Thu Mar 03, 2011 10:13 am

Re: Week number to Private data

Post 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.
User avatar
Terkelsen
Advanced member
Posts: 297
Joined: Thu Sep 08, 2011 5:08 pm
Contact:

Re: Week number to Private data

Post 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.
Post Reply