tags:

views:

293

answers:

1

For a check i need yesterday's date at 10:00pm in a variable.

I get yesterdays Date and current Time with

$a = (get-date).AddDays(-1)

But how do i manipulate the time to 22.00 and leave the variable still as Date-Object?

+4  A: 

Use DateTime.Today as opposed to DateTime.Now (which is what Get-Date returns) because Today is just the date with 00:00 as the time, and now is the moment in time down to the millisecond. (from masenkablast)

> [DateTime]::Today.AddDays(-1).AddHours(22)
Thursday, March 11, 2010 10:00:00 PM
James Kolpack
Works perfect, thanks!
icnivad
wow I have this long complicated function in one of my scripts that does what this 1 line does. Yay for stupidity on my part.
percent20