E.g.
01/15/2024
1/15/2024
1/15/24
01/03/2024
1/3/2024
1/3/24
Unless you write something in VBscript or whatever Excel uses now, it’s a nightmare.
E.g.
01/15/2024
1/15/2024
1/15/24
01/03/2024
1/3/2024
1/3/24
Unless you write something in VBscript or whatever Excel uses now, it’s a nightmare.
function dateFix() { var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet1"); var dateRange = sheet.getRange("A:A"); var dateValues = dateRange.getValues();
for (var i = 0; i < dateValues.length; i++) {
if (dateValues[i][0]) {
var fixedDate = fixDate(dateValues[i][0]);
if (fixedDate) {
sheet.getRange(i + 1, 2).setValue(fixedDate);
}
}
}
}function fixDate(dateString) { var datePattern = /^(\d{1,2})\/(\d{1,2})\/(\d{2}|\d{4})$/; var match = dateString.match(datePattern);
if (!match) {
return null;
}
var month = match[1].padStart(2, '0');
var day = match[2].padStart(2, '0');
var year = match[3];
if (year.length === 2) {
year = '20' + year;
}
return month + '/' + day + '/' + year;
}The workaround, at least for CSVs, is to do an import via "Get Data" -> "From Text (legacy)" and tag the relevant column as "date". This doesn't always work though.
https://support.microsoft.com/en-us/office/format-a-date-the...
If I was going to drop my hackerman shades and pull up to an Excel code golf competition this is the "fewest total characters using a single cell" I could come up with: =REGEXREPLACE(A1 "^0?(\d{1,2})\/0?(\d{1,2})\/(..)?(\d{2})$", "20$3/$2/$1")
it is unforgivable that a program used for timeseries data can't interpret an ISO 8901 without third party macros
It's precisely for parsing dates but on a column with 1-digit vs. 2-digit days/months and 2-digit vs. 4-digit years (all in d/m/y format, mind you), it fails in one instance or the other.
I expect it gets your example there right, but you may have other issues in mind that you didn't push into the example.
The examples you gave are in m/d/y format though, and DATEVALUE() parses your examples correctly into Jan 15th, 2024 and January 3rd, 2024.
DATEVALUE() parses ambiguous short date formats (e.g. 1/3/24) using the short date format specified in the Region settings of Windows Control Panel. So if you want to parse d/m/y format, you can try changing the settings there.