-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFind-WeekNumberByDate.ps1
More file actions
70 lines (65 loc) · 1.93 KB
/
Copy pathFind-WeekNumberByDate.ps1
File metadata and controls
70 lines (65 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
function Find-WeekNumberByDate
{
<#
.Synopsis
Will check a given date for its week number.
.DESCRIPTION
Resolves the number of the week in which the day of the
given month falls.
.PARAMETER Date
The date(s) to amalyze.
.EXAMPLE
Find-WeekNumberByDate '3/30/2018' |fl
Ordinal : 5th
OrdinalWeekday : 5th Friday
WeekNumber : 5
isLastWeek : True
OrdinalWithMonth : 5th Friday of March
Date : 3/30/2018 12:00:00 AM
DayOfWeek : Friday
Month : March
.INPUTS
This function accepts datetime objects.
.OUTPUTS
Output from this cmdlet is a PsCustomObject.
#>
[CmdletBinding(DefaultParameterSetName='MonthRange',
PositionalBinding=$false)]
[OutputType([datetime[]])]
Param
(
# The date(s) to amalyze.
[Parameter(Position=0,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true)]
[datetime]
$Date=(Get-Date)
)
Begin
{
}
Process
{
# Week number is truncated dividend of 7, plus 1
$WeekNumber = [math]::Truncate(($Date.Day) / 7) + 1
# Determine the ordinal
$Suffix = Get-OrdinalSuffix -num $WeekNumber
# Determine if this date is in the last week or not
$LastDayInMonth = Resolve-LastDayInMonth -Date $Date
$isLastWeek = ($Date.Day + 6) -ge $LastDayInMonth
# output all the properties.
New-Object psobject -Property @{
Date = $Date
isLastWeek = $isLastWeek
WeekNumber = $WeekNumber
DayOfWeek = $Date.DayOfWeek
Month = $Date.ToString('MMMM')
Ordinal = "$($WeekNumber)$($Suffix)"
OrdinalWeekday = "$($WeekNumber)$($Suffix) $($Date.DayOfWeek)"
OrdinalWithMonth = "$($WeekNumber)$($Suffix) $($Date.DayOfWeek) of $($Date.ToString('MMMM'))"
}
}
End
{
}
}