0

I have a single ligne column (Called : Next Due Diligence Date) in my sharepoint list where i have a date with "MM-YYYY" format. I want to parse it to "01/MM/YYYY"

For this, I tried the Code below :

    $dateString =$IM["Next Due Diligence Date"]
    $format ="01/MM/YYYY"
    $start = [datetime]::parseexact($dateString, $format, $null)

I have this Error : Exception calling "ParseExact" with "3" argument(s): "String was not recognized as a valid DateTime."

1 Answer 1

1

If you are sure that $IM["Next Due Diligence Date"] contains value in "MM-YYYY" format, you could do something like this:

$dateString =$IM["Next Due Diligence Date"]
$dateStringParts = $dateString.Split('-');
$start  = New-Object DateTime([Int32]::Parse($dateStringParts[1]), [Int32]::Parse($dateStringParts[0]), 1)

and after that you could format the date with this:

$start.ToString("dd/MM/yyyy")

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.