PoshCode Archive  Artifact [5c1e738487]

Artifact 5c1e738487d20b581ee0c7f91379b22f8449f9a238fe86bedd550a1da9b92975:

  • File Get-CalendarWeek.ps1 — part of check-in [ff031772c9] at 2018-06-10 12:56:59 on branch trunk — This function calculates the calendar week to a given date. It either takes a given date or retrieves the current date. (user: Holger Adam size: 1007)

# encoding: ascii
# api: powershell
# title: Get-CalendarWeek
# description: This function calculates the calendar week to a given date. It either takes a given date or retrieves the current date.
# version: 0.1
# type: function
# author: Holger Adam
# license: CC0
# function: Get-CalendarWeek
# x-poshcode-id: 1392
# x-archived: 2016-04-22T18:54:34
# x-published: 2010-10-13T07:54:00
#
# Update: Now using CultureInfo for global usage.
# Update: Move $null check to a default Date value
# Examples:
# Get-CalendarWeek
# Get-Date | Get-CalendarWeek
#
# Get-CalendarWeek by Holger Adam
# Simple function to retrieve the calendar week to a given or the current date.

function Get-CalendarWeek {
	param(
		$Date = (Get-Date)
	)
	
	# get current culture object
	$Culture = [System.Globalization.CultureInfo]::CurrentCulture
	
	# retrieve calendar week
	$Culture.Calendar.GetWeekOfYear($Date, $Culture.DateTimeFormat.CalendarWeekRule, $Culture.DateTimeFormat.FirstDayOfWeek)
}