0

I've got some date data in a Google drive sheet which is imported from a CSV.

The date data is formatted as either dd/mm/yy or dd.mm.yy as hard key data (eg. not formatted as a date)

I got to format > number > date but it doesn't work.

Any idea how I can format these as dates in Google sheets ?

I've made an example spreadsheet here: https://docs.google.com/spreadsheets/d/1FyU526G55dVwKDryaNS1Dz_U2XZpIa9chDCJDcRxQzg/edit#gid=0

2 Answers 2

1

Your spreadsheet is in a locale that currently uses the dd/mm/yyyy data format. The data has apparently been imported while the spreadsheet was set to a locale with another date format, which has caused the data to not get converted but stored as text strings instead.

When your csv data is in a date format that differs from that of the spreadsheet, it will not be detected as dates, or worse, will get detected incorrectly, with days and months getting swapped.

To fix the problem, set File > Spreadsheet settings > Locale to a locale whose date format matches that of the data, then change the locale to your real locale.

Your sample spreadsheet already has data that consists of text strings that look like dates. You can convert them to numeric dates with this formula in cell C3:

=arrayformula( if( istext(A3:A), value( regexreplace(A3:A, "(\d\d?)[^\d](\d\d?)[^\d](\d\d\d?\d?)", "$1-$2-$3") ), iferror(1/0) ) )

Format the result column as Format > Number > Date.

Note that while this formula works with the sample data you show in the spreadsheet, it will not give correct results with data that has been incorrectly converted to dates. It happens to work here because all the dates from row 17 down have a number that is greater than 12 in the first position. This number cannot be a month, and the data has apparently been imported with the US locale which has caused the data to not get converted but stored as text strings instead.

See this answer for an explanation of how date and time values work in spreadsheets.

1

Since your sheet's locale is United Kingdom you can try the following in a new column (change ranges per your needs)

=ArrayFormula(IF(B3:B="",, 
       IFERROR(REGEXREPLACE(B3:B,"\.","/")^1,B3:B)))

Now format this column as format > number > date.

enter image description here

If you need a more general formula use

=ArrayFormula(IF(B3:B="",, 
       IFERROR(REGEXREPLACE(B3:B,"(\d+).(\d+).(\d+)","$1/$2/$3")^1,B3:B)))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.