Compare yesterday date & current date from log file

Welcome Forums General PowerShell Q&A Compare yesterday date & current date from log file

This topic contains 1 reply, has 2 voices, and was last updated by

12 months ago.

  • Author
  • #94164

    Points: 11
    Rank: Member

    I have a log file, I need compare previous date end time & current date end time (based on the system).
    If the current end time does not find in the log, trigger an email.

    If current end time finds in the log, attach the log.

    Log details:

    Data Start Time – 2018-02-18 22.30.00
    Data End Time – 2018-02-19 00.55.50
    Time taken for whole process – 8544

    Data Start Time – 2018-02-19 22.30.00


    $log = Get-ChildItem c:\opscripts\test\server01\test.log
    $results = switch -Regex -File $log {
        'Data (Start|End) .*' {$Matches[0]}
        'Time taken for whole process.*' {$Matches[0]}


  • #94165

    Points: 642
    Helping Hand
    Rank: Major Contributor

    To compare dates and times you should convert them to DateTime objects or TimeSpan objects and compare them this way. Something like this could help you to start:

    [datetime]::ParseExact('2018-02-18 22.30.00', 'yyyy-MM-dd', $null)

The topic ‘Compare yesterday date & current date from log file’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort