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

 
Participant
9 months ago.

  • Author
    Posts
  • #94164

    Participant
    Points: 0
    Rank: Member

    Hi,
    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

    Script:

    $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]}
    }

    -Kalyan

  • #94165

    Participant
    Points: 170
    Helping Hand
    Rank: Participant

    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 HH.mm.ss', $null)

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