PowerShell: Get today’s date only
Recently I needed to get a [System.DateTime] object with today’s date only (no time information). Sounds easy, right?
At first I found “Get-Date -displayhint date” on http://technet.microsoft.com/en-us/library/ee176845.aspx While the output looks nice, it only affects console string display. The underlying object still has full timestamp information.
I ended up coding “New-Object "System.DateTime" -ArgumentList (Get-Date).Year, (Get-Date).Month, (Get-Date).Day” as the clean way to create a new object with today’s date only. This allowed the rest of my code to then work perfectly. Hope this helps somebody else too! ![]()
New-Object "System.DateTime" -ArgumentList (Get-Date).Year, (Get-Date).Month, (Get-Date).Day
