All messages posted to this blog are provided "AS IS" with no warranties, and confer no rights.
Information on unreleased products are subject to change without notice.
Dates related to unreleased products are estimates and are subject to change without notice.
The content of this site are personal opinions and might not represent the Microsoft Corporation view.
The information contained in this blog represents my view on the issues discussed as of the date of publication.
You should not consider older, out-of-date posts to reflect my current thoughts and opinions.
© Copyright 2004-2012 by Jose Barreto. All rights reserved.
Follow @josebarreto on Twitter for updates on new blog posts.
I was trying to figure out why people use the more complicated [System.DateTime]::Now instead of the simple Get-Date.
They do the same thing and they both return an object of type "System.DateTime".
PS C:\> Get-DateThursday, April 08, 2010 10:46:48 PM PS C:\> [System.DateTime]::NowThursday, April 08, 2010 10:46:59 PM
PS C:\> Get-DateThursday, April 08, 2010 10:46:48 PM
PS C:\> [System.DateTime]::NowThursday, April 08, 2010 10:46:59 PM
The only possible different is the performance. Yes, Get-Date is slightly slower, but they both really do the job in less than a millisecond. I had fun testing it, though, creating a a PowerShell one-liner to measure how long they each take to run, with 5,000 samples of each and discarding any result that did not show up at least 10 times out of the 5,000. I didn't even have to launch Excel...
PS C:\> 1..5000 | %{ (((Measure-Command {[System.DateTime]::Now}).TotalMilliseconds).ToString()).Substring(1,3) } | Group | ?{$_.Count -gt 10} | Sort Name | Select Count, Name Count Name ----- ---- 4888 .03 43 .04 15 .05 26 .07PS C:\> 1..5000 | %{ (((Measure-Command {Get-Date}).TotalMilliseconds).ToString()).Substring(1,3) } | Group | ?{$_.Count -gt 10} | Sort Name | Select Count, Name Count Name ----- ---- 2288 .11 2224 .12 246 .13 85 .14 32 .15 14 .16 17 .17
PS C:\> 1..5000 | %{ (((Measure-Command {[System.DateTime]::Now}).TotalMilliseconds).ToString()).Substring(1,3) } | Group | ?{$_.Count -gt 10} | Sort Name | Select Count, Name
Count Name ----- ---- 4888 .03 43 .04 15 .05 26 .07PS C:\> 1..5000 | %{ (((Measure-Command {Get-Date}).TotalMilliseconds).ToString()).Substring(1,3) } | Group | ?{$_.Count -gt 10} | Sort Name | Select Count, Name
Count Name ----- ---- 2288 .11 2224 .12 246 .13 85 .14 32 .15 14 .16 17 .17
So, unless you care about the difference of doing it in 0.03 milliseconds instead of 0.115 milliseconds, they are pretty much the same. :-)
my only pet peeve is why does the property ".date" show the day and time which is different then ".datetime" I don't think ."date" should show the time at all!