1

CSV source exemple:

"Requested Quantity","Unit of Measure","Requested Date","Forecast Timing Qualifier","Rating"
"4.00 ","EA","26.09.2022","W","DOA1"
"12.00 ","EA","27.09.2022","W","DOA1"

I need to remove the last 3 Characters to Requested Quantity and I need to convert the Requested Date format to Month.Day.Year for each line.

Input : "4.00 ","EA","26.09.2022","W","DOA1" Output : "4","EA","09/26/2022","W","DOA1"

I got the Requested quantity ok but I need some help with converting the date portion.

Thanks

1
  • Please add your code to the question Commented Mar 8, 2022 at 18:19

1 Answer 1

2

For the Requested Quantity column you can use the -replace operator to remove the dot and everything after. For the date column, use [Datetime]::ParseExact() to parse the existing format, then convert back to a string with the desired format:

Import-Csv path\to\source.csv |ForEach-Object {
    # Cut the trailing decimals off the quantity
    $_.'Requested Quantity' = $_.'Requested Quantity' -replace '\..*$'

    # Parse and re-format date column
    $_.'Requested Date' = [datetime]::ParseExact($_.'Requested Date', 'dd.MM.yyyy', $null).ToString('MM/dd/yyyy')

    # output the modified object for export
    $_
} |Export-Csv path\to\output.csv -NoTypeInformation
Sign up to request clarification or add additional context in comments.

2 Comments

The output I get is not correct for the date. "4","EA","09-26-2022","W","DOA1" It looks like it take my system date separators not /
Thanks for putting me on the right track Mathias. I ended up changing the Request Date Parse to # Parse and re-format date column $_.'Requested Date' = [datetime]::ParseExact($_.'Requested Date', 'dd.MM.yyyy', $null).ToString('MM\/dd\/yyyy') to get it to work correctly.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.