User talk:Jontah88

From Rosetta Code

Hello Guys,

I Modified the Last Sunday powershell script posted here, and its working. But I cant make it to have an output of txt file. Not sure how I can have an output in txt file.


function 4th-OR-Last

{

   param(
    [Int][ValidatePattern("[1-9][0-9][0-9][0-9]")]$year,
    [String][validateset('Sunday','Saturday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday')]$dayofweek
   )
   $date = (Get-Date -Year $year -Month 1 -Day 1)
   $Weekday='Thursday'
     
   while($date.DayOfWeek -ne $dayofweek) {$date = $date.AddDays(1)}
   While($date.DayOfWeek -ine $Weekday) {$date=$date.AddDays(7)}
   While ($date.Year -eq $year) {
   
   If ($date.day -ge "22" -and $date.day -le "28")
   {Write-Host $date.ToString("'DCA-4thThur@6-10pmPT, 4th Thursday,' MMMM dd, yyyy, '6-10pmPST'") }
   Elseif ($date.day -ge "29")
   {Write-Host $Date.ToString("'DCA-4thThur@6-10pmPT, Last Thursday,' MMMM dd, yyyy, '6-10pmPST'") }
   $date = $date.AddDays(7)
            }
           
                

}

   4th-OR-Last 2017 "Thursday"


And I have an output below:

DCA-4thThur@6-10pmPT, 4th Thursday, January 26, 2017, 6-10pmPST DCA-4thThur@6-10pmPT, 4th Thursday, February 23, 2017, 6-10pmPST DCA-4thThur@6-10pmPT, 4th Thursday, March 23, 2017, 6-10pmPST DCA-4thThur@6-10pmPT, Last Thursday, March 30, 2017, 6-10pmPST DCA-4thThur@6-10pmPT, 4th Thursday, April 27, 2017, 6-10pmPST DCA-4thThur@6-10pmPT, 4th Thursday, May 25, 2017, 6-10pmPST DCA-4thThur@6-10pmPT, 4th Thursday, June 22, 2017, 6-10pmPST DCA-4thThur@6-10pmPT, Last Thursday, June 29, 2017, 6-10pmPST DCA-4thThur@6-10pmPT, 4th Thursday, July 27, 2017, 6-10pmPST DCA-4thThur@6-10pmPT, 4th Thursday, August 24, 2017, 6-10pmPST DCA-4thThur@6-10pmPT, Last Thursday, August 31, 2017, 6-10pmPST DCA-4thThur@6-10pmPT, 4th Thursday, September 28, 2017, 6-10pmPST DCA-4thThur@6-10pmPT, 4th Thursday, October 26, 2017, 6-10pmPST DCA-4thThur@6-10pmPT, 4th Thursday, November 23, 2017, 6-10pmPST DCA-4thThur@6-10pmPT, Last Thursday, November 30, 2017, 6-10pmPST DCA-4thThur@6-10pmPT, 4th Thursday, December 28, 2017, 6-10pmPST

PS C:\>