PowerShell: Comparing dates

前端 未结 3 927
被撕碎了的回忆
被撕碎了的回忆 2021-02-06 21:01

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         


        
3条回答
  •  被撕碎了的回忆
    2021-02-06 21:50

    I wanted to show how powerful it can be aside from just checking "-lt".

    Example: I used it to calculate time differences take from Windows event view Application log:

    Get the difference between the two date times:

    PS> $Obj = ((get-date "10/22/2020 12:51:1") - (get-date "10/22/2020 12:20:1 "))
    

    Object created:

    PS> $Obj
    
    
    Days              : 0
    Hours             : 0
    Minutes           : 31
    Seconds           : 0
    Milliseconds      : 0
    Ticks             : 18600000000
    TotalDays         : 0.0215277777777778
    TotalHours        : 0.516666666666667
    TotalMinutes      : 31
    TotalSeconds      : 1860
    TotalMilliseconds : 1860000
    

    Access an item directly:

    PS> $Obj.Minutes
    31
    

提交回复
热议问题