本文介绍了PowerShell:比较日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在查询日期的数据源.根据我要搜索的项目,它可能有多个与其关联的日期.
I am querying a data source for dates. Depending on the item I am searching for, it may have more than date associated with it.
get-date ($Output | Select-Object -ExpandProperty "Date")
输出示例如下:
Monday, April 08, 2013 12:00:00 AM
Friday, April 08, 2011 12:00:00 AM
我想比较这些日期并返回哪个日期更远.
I would like to compare these dates and return which one is set further out into the future.
推荐答案
由于 Get-Date
返回一个 DateTime 对象,您可以直接比较它们.一个例子:
As Get-Date
returns a DateTime object you are able to compare them directly. An example:
(get-date 2010-01-02) -lt (get-date 2010-01-01)
将返回 false.
这篇关于PowerShell:比较日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!