Reputation: 301
I'm trying to filter out events from a csv file for a timestamp column where the date format is like 1/25/2016 13:39 but not sure how to do this? Ideally I'd like to be able to take the week before last range of dates so if I run it today 2/9/2016, it would grab 1/24/2016 thru 1/30/2016 and ignore the time of day stamp.
Upvotes: 2
Views: 9375
Reputation: 1441
You could try something like this:
$today = (Get-Date)
$startDate = $today.Date.AddDays(-14 - [int]$dt.DayOfWeek) # Assuming Sunday's DayOfWeek is 0 in your culture
$endDate = $startDate.AddDays(7)
$result = $csv | ConvertFrom-Csv | Where-Object { [DateTime]$_.Timestamp -ge $startDate -and [DateTime]$_.Timestamp -lt $endDate }
Upvotes: 3