How to extract date from string

Welcome Forums General PowerShell Q&A How to extract date from string

This topic contains 2 replies, has 3 voices, and was last updated by

1 year ago.

  • Author
  • #97917

    Points: 0
    Rank: Member

    I have a string Certificate Expiration Date: 2/23/2022 7:39 AM and from this I want to extract the date only in the format Wednesday, February 23, 2022 7:39:23 AM and store it in a variable in date format

    Any script to achieve this will be helpful

  • #97920

    Points: 3
    Rank: Member

    ([datetime]"2/23/2022 7:39 AM").datetime

  • #97953

    Points: 38
    Rank: Member

    Create a substring to remove the beginning "Certificate Expiration Date: ", then cast it to a DateTime format.

    $string = "Certificate Expiration Date: 2/23/2022 7:39 AM"
    $dateTimeString = [DateTime]$string.Substring($string.IndexOf(":")+1)

The topic ‘How to extract date from string’ is closed to new replies.

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