PoshCode Archive  Artifact [1b9712748c]

Artifact 1b9712748c1d1d92f9748a8e6d09c9c57ae2951e7d37d5fc05cab741bd979046:

  • File Get-CalendarWeek.ps1 — part of check-in [e06f4173ce] 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: 1043)

# 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: 1391
# x-derived-from-id: 1392
# x-archived: 2016-04-26T06:31:14
# x-published: 2010-10-13T00:49:00
#
# Update: Now using CultureInfo for global usage.
# 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
	)
	
	# check date input
	if ($Date -eq $null)
	{
		$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)
}