Reputation: 496
I have a script that provides the sunrise and sunset times yesterday ($sunrise and $sunset, formatted as yyyy-MM-dd HH:mm:ss). I have a file (could be txt or csv) where the first column has a timestamp in the format of yyyy-MM-dd HH:mm:ss and the second column has a number in the format of XX.X. Using Powershell Get-Content, I am trying to return all of the values that are between the sunrise and sunset times, inclusive. Using Select, I can get singular values, but I can't figure out how to get multiple, let alone a range.
Get-Content C:\uv.txt | select (between $sunrise & $sunset)
Input (uv.txt):
2020-08-11 06:00:00 0.0
2020-08-11 07:00:00 0.0
2020-08-11 08:00:00 0.6
2020-08-11 09:00:00 1.4
2020-08-11 10:00:00 4.2
2020-08-11 11:00:00 6.2
2020-08-11 12:00:00 8.4
2020-08-11 13:00:00 9.3
2020-08-11 14:00:00 9.2
2020-08-11 15:00:00 7.6
2020-08-11 16:00:00 5.6
2020-08-11 17:00:00 3.3
2020-08-11 18:00:00 1.6
2020-08-11 19:00:00 0.5
2020-08-11 20:00:00 0.0
2020-08-11 21:00:00 0.0
2020-08-11 22:00:00 0.0
Simplified script that is not working (no output in console or if I send to out-file):
$sunrise = "2020-08-12 06:32:17"
$sunset = "2020-08-12 20:06:33"
Get-Content C:\daily_values_uv.txt | Where-Object { $_ -ge $sunrise -and $_ -le $sunset }
Upvotes: 0
Views: 1404
Reputation: 174825
Thanks to the big endian date format, you can do:
Get-Content C:\uv.txt | Where-Object { $_ -gt $sunrise -and $_ -lt $sunset }
Upvotes: 3