Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Powershell's Get-date: How to get Yesterday at 22:00 in a variable?

Tags:

powershell

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?

like image 877
icnivad Avatar asked Mar 12 '10 15:03

icnivad


People also ask

How can I get yesterday's date?

How do you get yesterdays' date using JavaScript? We use the setDate() method on yesterday , passing as parameter the current day minus one. Even if it's day 1 of the month, JavaScript is logical enough and it will point to the last day of the previous month.

How do I get yesterday's date in python?

You just have to subtract no. of days using 'timedelta' that you want to get back in order to get the date from the past. For example, on subtracting two we will get the date of the day before yesterday.

How can I get yesterday date in PHP?

Using time() to Get Yesterday's Date in PHP The time() function returns the current timestamp. If we subtract its value, then we get the timestamp of the same time yesterday.


1 Answers

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 
like image 150
James Kolpack Avatar answered Sep 19 '22 18:09

James Kolpack