简体   繁体   English

如何在powershell中的2个日期之间识别具有特定日期值的日期列表

[英]How to identify a list of dates with a specific day value between 2 dates in powershell

So I have this code (thanks to @reeeky2001 ) that answer my other post Trying to find a way to list all friday dates between 2 dates in powershell :所以我有这个代码(感谢@reeeky2001 )回答我的另一篇文章试图找到一种方法来列出powershell中2个日期之间的所有星期五日期

$FiscalStart = [datetime]'2019-03-31'
$date2 = Get-Date -Hour 0 -Minute 0 -Second 0
$EvaluateDates = 1..($date2 - $FiscalStart).Days | % {$($FiscalStart).AddDays($_)} | ? {$_.DayOfWeek -eq 'monday'}
$EvaluateDates

So let's say we are on feb 09, 2020. if I run the following code, the last monday will be feb 03, 2020. How could I exclude the last date, So the next monday (feb 10, 2020) is in the future?假设我们在 2020 年 2 月 9 日。如果我运行以下代码,最后一个星期一将是 2020 年 2 月 3 日。我怎么能排除最后一个日期,所以下一个星期一(2020 年 2 月 10 日)是在未来? How could I exclude any dates where the next monday would be in the future ?我怎么能排除下一个星期一将在未来的任何日期? Assuming this code could be run anyday of the week...假设这段代码可以在一周中的任何一天运行......

At the end I added "-and $_ -lt (get-date)"最后我添加了“-and $_ -lt (get-date)”

$FiscalStart = [datetime]'2019-12-31'
$date2 = Get-Date -Hour 0 -Minute 0 -Second 0
1..($date2 - $FiscalStart).Days | % {($FiscalStart).AddDays($_)} | 
  ? { $_.DayOfWeek -eq 'monday' -and $_ -lt (get-date)}


Monday, January 6, 2020 12:00:00 AM
Monday, January 13, 2020 12:00:00 AM
Monday, January 20, 2020 12:00:00 AM
Monday, January 27, 2020 12:00:00 AM
Monday, February 3, 2020 12:00:00 AM

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM