none
Modification of Time Format Values in CSV using powershell RRS feed

  • Question

  • Hi Experts,

    I have a CSV with following Details,

    NAME,  ArrivalTime

    Robert, 17:00

    Julie,     18:00

    Serigo,   06:30

    (Tab Delimited for legibility )

    I am trying to reduce the time value by 30 minutes, since I want to reduce the time for all the values of column ArrivalTime,

    $csv=Import-Csv D:\Inputfile.csv
    $csv| foreach-object {
    String.Time($reduce='00:30:00')
    [datetime]::ParseExact($csv.Time, "HH:mm", $null)
    $_.Time =$_.Time.replace("$_.Time","$_.Time-$reduce")
    }
    $csv|Export-csv D:\Outputfile.csv

    Like Expected Output csv:

    NAME,  ArrivalTime

    Robert, 16:30

    Julie,     17:30

    Serigo,   06:00,

    Kindly help me out ..with your suggestions..


    Monday, November 17, 2014 9:53 AM

Answers

  • Try it like this"

    $csv=Import-Csv D:\Inputfile.csv
    $csv| 
       ForEach-Object{
          $_.Time=([datetime]$($_.Time)).AddMinutes(-30).ToString('HH:mm')
       }
    $csv|Export-csv D:\Outputfile.csv


    ¯\_(ツ)_/¯

    Monday, November 17, 2014 11:28 AM

All replies

  • Try it like this"

    $csv=Import-Csv D:\Inputfile.csv
    $csv| 
       ForEach-Object{
          $_.Time=([datetime]$($_.Time)).AddMinutes(-30).ToString('HH:mm')
       }
    $csv|Export-csv D:\Outputfile.csv


    ¯\_(ツ)_/¯

    Monday, November 17, 2014 11:28 AM
  • Thanks :)

    It works as desired.

    Monday, November 17, 2014 11:51 AM