Powershell - amend date format to values in CSV column

James

I'm looking for a PowerShell script for the following ...

I have a CSV spread sheet which automatically downloads from a website, the 2nd column of the spread sheet is a date value in the UK format dd/mm/yyyy. I'd like a script that will change the date format of all values in column 2 to the US date format yyyy/mm/dd.

I'm importing the CSV into a MySQL database using LOAD DATA INFILE and at present the dates are going in 2017/02/15 when they should be 2015/02/17.

An example of the CSV file format is as follows ...

Col1,Col2,Col3,Col4
Value1,17/02/15,Value3,Value4
Value1,18/02/15,Value3,Value4
Value1,19/02/15,Value3,Value4

I need it to become ...

Col1,Col2,Col3,Col4
Value1,2015-02-17,Value3,Value4
Value1,2015-02-18,Value3,Value4
Value1,2015-02-19,Value3,Value4
Loïc MICHEL

one way could be (will replace all date in UK format to US format, regardless of the column):

(get-content c:\file.csv) -replace "(\d{2})\/(\d{2})\/(\d{4})", '$3/$2/$1'  

if you want to save the result pipe to set-content :

(get-content c:\file.csv) -replace "(\d{2})\/(\d{2})\/(\d{4})", '$3/$2/$1'  |sc c:\file.csv 

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Format a csv date column using mysql load data in file

From Dev

Powershell Format-Table to CSV

From Dev

Sorting csv column by date

From Dev

PowerShell date format not accepted in SQL

From Dev

PHP Date Export To CSV Format

From Dev

Format date in a column using awk

From Dev

format date column in csv with bash script

From Dev

Change date format in CSV using PowerShell

From Dev

Is it possible to change format of date values in a MySQL column?

From Dev

Replace column values with Powershell

From Dev

PowerShell - formatting date to yyMMdd format

From Dev

How to Format a Date Column in Pandas?

From Dev

Creating new column in csv using powershell with dynamic values

From Dev

Change the format of the date column in Thunderbird

From Dev

Sorting csv column by date

From Dev

PowerShell date format not accepted in SQL

From Dev

Convert date format in csv by powershell

From Dev

Sql Query Results to CSV format doesn't include the correct date values

From Dev

PHP Date Export To CSV Format

From Dev

Changing the format of a date in a column of a comma delimited file .csv in unix

From Dev

How to format a date field in powershell?

From Dev

Powershell Date format

From Dev

Amend column values according to timedelta and index

From Dev

Change date format in PowerShell Export SQL to CSV script

From Dev

PowerShell date format not behaving

From Dev

Sort CSV on date column in Python while ignoring null cell values

From Dev

convert a datatable column date format

From Dev

Change Datatable Column Date Format

From Dev

How to import date column from csv in python in format d/m/y