title: Convert date format to CSV export
body: <p>I'm new to Poweshell, and I made a script that the result of an SQL Select is exported to csv. However I have two columns that are in the date format mm-dd-yyyy and I would like it to be in the format yyyy-MM-dd HH: mm: ss.fff. I was able to transform just one column, in the other I couldn't find a way to convert.</p>
  
  <p>Could someone help me to convert the two columns?</p>
  
  <pre><code>#Connect to SQL and run QUERY 
  $SQLServer = "xxxx" 
  $SQLDBName = "xxxx"
  $SQLUsername = "xxxx"
  $SQLPassword = "nxxx"
  
  $OuputFile = "c:\SQL_Export.csv"
  
  $SqlQuery = "SELECT  
      rtrim(HANDLE) as Handle,
      rtrim(EMPRESA) as Empresa,
      rtrim(FILIAL) as Filial,
      rtrim(OPERACAO) as Operacao,
      rtrim(PESSOA) as Pessoa,
      rtrim(dataemissao) as Dataemissao,
      rtrim(documentodigitado) as Documentodigitado,
      rtrim(dataultimaliq) as Dataultimaliq,
      rtrim(ehprevisao) as Ehprevisao,
      rtrim(status) as Status,
      rtrim(entradasaida) as Entradasaida
    FROM [$SQLDBName].[dbo].[FN_DOCUMENTOS]
    where DATAULTIMALIQ &gt;= '20200101'
    ORDER BY handle ASC"
  
  ##Delete the output file if it already exists
  If (Test-Path $OuputFile ){
      Remove-Item $OuputFile
  }
  
  Write-Host "INFO: Exporting data from $SQLDBName to $OuputFile" -foregroundcolor white -backgroundcolor blue
  
  ## - Connect to SQL Server using non-SMO class 'System.Data':
  $SqlConnection = New-Object System.Data.SqlClient.SqlConnection 
  $SqlConnection.ConnectionString = "Server = $SQLServer; Database = $SQLDBName; User ID = $SQLUsername; Password = $SQLPassword"
  
  $SqlCmd = New-Object System.Data.SqlClient.SqlCommand 
  $SqlCmd.CommandText = $SqlQuery
  $SqlCmd.Connection = $SqlConnection
  
  $SqlAdapter = New-Object System.Data.SqlClient.SqlDataAdapter 
  $SqlAdapter.SelectCommand = $SqlCmd
  
  $DataSet = New-Object System.Data.DataSet 
  $SqlAdapter.Fill($DataSet) 
  $SqlConnection.Close() 
  
  #Output RESULTS to CSV
  $DataSet.Tables[0] | select-Object -ExcludeProperty Dataemissao @{Name="Dataemissao";Expression={([datetime]$_.Dataemissao).ToString("yyyy-MM-dd HH:mm:ss.fff")}}, * | Export-Csv $OuputFile
  (Get-Content $OuputFile) | Foreach-Object {$_ -replace '"', ""} | Set-Content $OuputFile -Encoding `UTF8`
  </code></pre>
  
  <p>the columns I need to convert are, "Dataemissao" and "Dataultimaliq"</p>