Compare yesterday date & current date from log file

This topic contains 1 reply, has 2 voices, and was last updated by  Olaf Soyk 3 months ago.

  • Author
    Posts
  • #94164

    Venkata Kalyan
    Participant

    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

    Olaf Soyk
    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)

You must be logged in to reply to this topic.