PoshCode Archive  Artifact Content

Artifact 1cd012839275b1d75ec2612f353e5a744cde5d579b7c5c5970a2771e89259dbe:

  • File datetime-Week.ps1 — part of check-in [0f3537d08c] at 2018-06-10 14:17:04 on branch trunk — This bit of code adds a Week ScriptProperty to datetime objects. The property returns the week of the year based on the current cultural settings. (user: Dale Thompson size: 731)

# encoding: ascii
# api: powershell
# title: [datetime].Week
# description: This bit of code adds a Week ScriptProperty to datetime objects. The property returns the week of the year based on the current cultural settings.
# version: 0.1
# type: script
# author: Dale Thompson
# license: CC0
# x-poshcode-id: 6500
# x-archived: 2016-09-03T23:44:52
# x-published: 2016-09-01T15:59:00
#
#
Update-TypeData -Force -TypeName DateTime -MemberType ScriptProperty -MemberName Week -Value {
   [System.Globalization.CultureInfo]$Culture = [System.Globalization.CultureInfo]::CurrentCulture
   return $Culture.Calendar.GetWeekOfYear($this, $Culture.DateTimeFormat.CalendarWeekRule, $Culture.DateTimeFormat.FirstDayOfWeek)
}