Question

I'm trying to get yesterday date to include the hour... for the start date, I'm using:

$startDate = (get-date).AddDays(-1).Date

This works as it returns the date with 12:00:00 AM at the end.

The end date is where I am stuck.. I need it end with 11:59:59 PM

Was it helpful?

Solution

If you want the end of today you need something like this:

$endDate =  (get-date).Date.AddDays(1).AddSeconds(-1)
  • Take now (get-date)
  • Remove all time part using .Date.
  • This is now the beginning of today.
  • Add a Day (.AddDays(1)) to make it the start of tomorrow.
  • Remove 1 second (.AddSeconds(-1)) to make it the end of today.

If you want the end of yesterday, remove the .AddDays(1) - it's unclear from your question.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top