Skip to content

Instantly share code, notes, and snippets.

@martin9700
Created July 24, 2014 21:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save martin9700/42d0ea641876fe63bca3 to your computer and use it in GitHub Desktop.
Save martin9700/42d0ea641876fe63bca3 to your computer and use it in GitHub Desktop.
Function Get-DateRange
{ <#
.SYNOPSIS
Find out all the dates inbetween the range of dates you specify
.DESCRIPTION
Simple function to return an array of date/time objects for all days inbetween the two dates
you specify.
.PARAMETER Start
Start date - this specifies the beginning of your range
.PARAMETER End
End date - this specifies the ending of your range. This date can be before OR after the Start
date.
.INPUTS
None
.OUTPUTS
[DateTime[]]
.EXAMPLE
Get-DateRange -Start 7/24/14 -End 7/1/14
Get all of the dates between the 24th to the 1st in reverse order. 24 DateTime objects will
be returned.
.EXAMPLE
Get-DateRange -End 8/1/14
Get all of the dates between today and 8/1/14. As of 7/14/14 that would be 8 dates.
.NOTES
Author: Martin Pugh
Twitter: @thesurlyadm1n
Spiceworks: Martin9700
Blog: www.thesurlyadmin.com
Changelog:
1.0 Initial Release
.LINK
#>
[CmdletBinding()]
Param (
[datetime]$Start = (Get-Date),
[datetime]$End = (Get-Date)
)
ForEach ($Num in (0..((New-TimeSpan -Start $Start -End $End).Days)))
{ $Start.AddDays($Num).Date
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment