I Remember Those Days (Until Christmas)

Sounds like Jeffery Snover’s daughter is eager for Christmas to arrive.  She was wanting to know how many days she had left to wait, so of course he wrote her a PowerShell function so that she could always find out.

I called my daughter over to explain what a wonderful tool PowerShell was.  I explained that if she ever wanted to get the date, all she had to do was to type “Get-Date”.  I then explained how she could cast a string containing a date into a datetime object:  [Datetime]“12/25/2011″ .  She didn’t get that one so I quickly moved on to explain that the reason why that mattered is that PowerShell is … well … powerful and that it does something called “object math”.  Object math (the ability to perform mathematical operations on any object which supports them) made everyone’s life easier because that means you can do things like:
PS> [DateTime]“12/25/2011″ – (Get-Date)

(read more)

I can picture this same conversation playing out at my house a few years back, and the solution sounds like something I would do.  The conversation would probably go something like this –

  • One of my kids [Oomk] : Hey dad, how many days until Christmas?
  • Me: I don’t know, let’s figure it out.
  • Oomk: That’s alright, I just thought you might know.
  • Me: No problem, let’s fire up PowerShell and…
  • Oomk: Dad, there’s a calendar right here…
  • Me: …and let’s see, we can do date addition…
  • Oomk: … we can just count, it will only take a minute
  • Me: Yes, but then we will have to count every time, if we take the time to write a function now…