I was running a data extraction process which accepted an ISO format start date and end date but because of the time span involved it would timeout before completion.

My solution was to break the dates into year-long chunks and run smaller extractions; each output would be saved into files named after the corresponding year. I was careful to use strings for the resulting dates so I could be absolutely sure of the yyyy-MM-dd ordering. This is what I came up with:

[DateTime] $fromDate = "2005-03-01"
[DateTime] $toDate = "2014-02-15"
$years = $toDate.Year - $fromDate.Year

0..$years | %{
	$partialFromDate = Get-Date $fromDate -Format "yyyy-MM-dd"
	if ($_ -ne 0) { # If it's not the first loop, start from January
		$partialFromDate = $fromDate.AddYears($_).Year.ToString() + "-01-01"
	}

	$partialToDate = Get-Date $toDate -Format "yyyy-MM-dd"
	if ($_ -ne $years) { # If it's not the last loop, end in December
		$partialToDate = $fromDate.AddYears($_).Year.ToString() + "-12-31"
	}

	"Year $($partialFromDate.Substring(0, 4)): $partialFromDate To $partialToDate"
	# Here: Run the ETL based on these dates and send to an appropriately named file
}
Year 2005: 2005-03-01 To 2005-12-31
Year 2006: 2006-01-01 To 2006-12-31
Year 2007: 2007-01-01 To 2007-12-31
Year 2008: 2008-01-01 To 2008-12-31
Year 2009: 2009-01-01 To 2009-12-31
Year 2010: 2010-01-01 To 2010-12-31
Year 2011: 2011-01-01 To 2011-12-31
Year 2012: 2012-01-01 To 2012-12-31
Year 2013: 2013-01-01 To 2013-12-31
Year 2014: 2014-01-01 To 2014-02-15