PowerShell: Get the week number for a given date

I was working on some reporting in PowerShell this afternoon, and needed to figure out if two dates are in the same week.

Here’s a quick little function that I put together to get the week number given a specific date. If no [datetime] object is passed in, it will simply return the week number for the current date.

A screenshot showing the Get-WeekNumber function in action. Called without the DateTime parameter, it outputs week 35. Given an input of "11 march 2015", it outputs 11.

Screenshot of Get-WeekNumber in action

Here’s the code:

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s