<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.technet.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Expert Solution for 2011 Scripting Games Beginner Event 7: Use PowerShell to Get the Number of Days Between Dates</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2011/04/26/expert-solution-for-2011-scripting-games-beginner-event-7-use-powershell-to-get-the-number-of-days-between-dates.aspx</link><description>Summary : Microsoft PFE, Michael Frommhold, uses Windows PowerShell to get the number of days between two dates as he solves Beginner Event 7 in one line of code. 
 Microsoft Scripting Guy, Ed Wilson, here. Michael Frommhold is the author for the expert</description><dc:language>en-US</dc:language><generator>Telligent Evolution Platform Developer Build (Build: 5.6.50428.7875)</generator><item><title>re: Expert Solution for 2011 Scripting Games Beginner Event 7: Use PowerShell to Get the Number of Days Between Dates</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2011/04/26/expert-solution-for-2011-scripting-games-beginner-event-7-use-powershell-to-get-the-number-of-days-between-dates.aspx#3424333</link><pubDate>Tue, 26 Apr 2011 15:35:53 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3424333</guid><dc:creator>jrussell97</dc:creator><description>&lt;p&gt;I can see that many people used the -f switch to format the output. &amp;nbsp;My question is how they discovered the switch. &amp;nbsp;I have looked at the help for write-host and I do not see that anywhere. &amp;nbsp;Perhaps an article about finding help would clear things up for me.&lt;/p&gt;
&lt;p&gt;Thanks&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3424333" width="1" height="1"&gt;</description></item><item><title>re: Expert Solution for 2011 Scripting Games Beginner Event 7: Use PowerShell to Get the Number of Days Between Dates</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2011/04/26/expert-solution-for-2011-scripting-games-beginner-event-7-use-powershell-to-get-the-number-of-days-between-dates.aspx#3424278</link><pubDate>Tue, 26 Apr 2011 12:58:48 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3424278</guid><dc:creator>cseiter</dc:creator><description>&lt;p&gt;Yeah, but what happens when it ends up only being 1 day? &amp;nbsp;I think mine was the only one that corrected for grammar with it changing the noun and verb to &amp;quot;There is 1 day left&amp;quot; instead of the usual &amp;quot;There are 1 days left&amp;quot;. &amp;nbsp; Your one-liner is much more elegant than mine. &amp;nbsp;I saw the subtract but didn&amp;#39;t investigate any farther on it to find the timespan.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3424278" width="1" height="1"&gt;</description></item><item><title>re: Expert Solution for 2011 Scripting Games Beginner Event 7: Use PowerShell to Get the Number of Days Between Dates</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2011/04/26/expert-solution-for-2011-scripting-games-beginner-event-7-use-powershell-to-get-the-number-of-days-between-dates.aspx#3424242</link><pubDate>Tue, 26 Apr 2011 10:48:46 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3424242</guid><dc:creator>Klaus Schulte</dc:creator><description>&lt;p&gt;Hello Michael,&lt;/p&gt;
&lt;p&gt;I probably could have written in german :-)&lt;/p&gt;
&lt;p&gt;Well, as everybody might know in between, I should rename to Mr.Ed ... oh, no! This one&amp;#39;s already taken ... Mr.Error :-)&lt;/p&gt;
&lt;p&gt;And really I just copied the solution and saved it to disk and called it, like you proposed:&lt;/p&gt;
&lt;p&gt;PS F:\Users\Klaus\SG2011&amp;gt; ./expert_be7.ps1 –EndDate 7/31/11 –MileStone &amp;quot;the end of the fiscal year&amp;quot;&lt;/p&gt;
&lt;p&gt;Get-Date : Der Parameter &amp;quot;Date&amp;quot; kann nicht gebunden werden. Der Wert &amp;quot;7/31/11&amp;quot; kann nicht in den Typ &amp;quot;System.DateTime&amp;quot; konvertiert wer&lt;/p&gt;
&lt;p&gt;den. Fehler: &amp;quot;Die Zeichenfolge wurde nicht als gültiges DateTime erkannt.&amp;quot;&lt;/p&gt;
&lt;p&gt;The judges might have said: This is not a working solution ... no stars!&lt;/p&gt;
&lt;p&gt;Of course, the solution does work in the USA and other countries using american date formats!&lt;/p&gt;
&lt;p&gt;So nobody might have seen anything bad in it.&lt;/p&gt;
&lt;p&gt;I really tried to make my solution work with any date format and used the approach to pass strings in&lt;/p&gt;
&lt;p&gt;and try to convert them to localized DateTime values, like that:&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;if (!($firstDate = $firstDay -as [DateTime]))&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;return &amp;quot;can&amp;#39;t convert firstDay: &amp;#39;$firstDay&amp;#39; to a DateTime&amp;quot;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt;This works like charm, but it might have even been better to allow DateTimes to be passed as parameter, too!&lt;/p&gt;
&lt;p&gt;Well besides the localization problem the solution doesn&amp;#39;t provide any error handling and I know, that the first&lt;/p&gt;
&lt;p&gt;thing that our users would enter into the pretty new function might be something like:&lt;/p&gt;
&lt;p&gt;./expert_be7.ps1 –EndDate Friday –MileStone &amp;quot;WOW! Only few days til the end of this week!&amp;quot; &lt;/p&gt;
&lt;p&gt;which will produce the same error as above of course!&lt;/p&gt;
&lt;p&gt;Another nice feature might have been to provide an additional parameter: -StartDate that could be used to&lt;/p&gt;
&lt;p&gt;provide an alternative to today&amp;#39;s date at nearly no cost!&lt;/p&gt;
&lt;p&gt;BUT: The worst aspect of the solution is, in my opinion, the fact that you do provide default values but these values&lt;/p&gt;
&lt;p&gt;will cause the same error as above on themselves!&lt;/p&gt;
&lt;p&gt;Param([String] $EndDate = &amp;quot;EndDate&amp;quot;, [String] $MileStone = &amp;quot;MileStone&amp;quot;)&lt;/p&gt;
&lt;p&gt;Setting $EndDate to a default of &amp;quot;EndDate&amp;quot; is really a bad idea! You might have used &amp;quot;12/31/2011&amp;quot; or any other &lt;/p&gt;
&lt;p&gt;reasonable default but not the string &amp;quot;EndDate&amp;quot;! &lt;/p&gt;
&lt;p&gt;Providing default values that will raise errors is really a &amp;quot;no go&amp;quot; imho.&lt;/p&gt;
&lt;p&gt;kind regards, Klaus&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3424242" width="1" height="1"&gt;</description></item></channel></rss>