Reputation: 137
I am importing a csv to an excel using powershell. Both of my columns have date-time in the following format:
2019-01-25T19:58:28.000Z
I want to convert the column to the following format "dd/MM/yyyy h:mm"
I tried the following two things and none of them worked:
[datetime]::ParseExact($fullinfo.A, "dd/MM/yyyy h:mm", $null)
$excel.Columns.item('b').NumberFormat = "dd/MM/yyyy h:mm"
$fullInfoSheet = $workbook.Worksheets.Item(1)
$fullInfoSheet.cells.item(1,1) = "Column A"
$fullInfoSheet.cells.item(1,2) = "Column B"
$fullinfolist = Import-Csv -Path $csvfullFile -Header A, B
$i = 2
foreach($fullinfo in $fullinfolist)
{
$fullInfoSheet.cells.item($i,1) = [datetime]::ParseExact($fullinfo.A, "dd/MM/yyyy h:mm", $null)
$fullInfoSheet.cells.item($i,2) = $fullinfo.B
$i++
}
$excel.Columns.item('b').NumberFormat = "dd/MM/yyyy h:mm"
Upvotes: 1
Views: 90
Reputation: 3923
This produces output in your desired format
$InputDate = '2019-01-25T19:58:28.000Z'
get-date $InputDate -Format 'dd/MM/yyyy h:mm'
Upvotes: 1