Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Excel Date Conversion from yyyymmdd to mm/dd/yyyy

I have been searching for about an hour on how to do this in Excel.

I have an Excel file that was created from an old system and I am pulling information from a SQL Server Database, I will be inputting the information back into the SQL Server Database and would like the Dates to match.

I have tried Creating a Custom Format, but I am unsure if I even did it Correctly. I found several places where they want to go the other way mm/dd/yyyy to yyyymmdd but they have not been helpful.

I am unfamiliar with using VBA in any Microsoft Products otherwise I am sure that this would be a simple Task.

I have two separate columns that need to be changed.

How do I Format the entire column from (float)yyyymmdd to a (Date)mm/dd/yyyy

like image 450
Malachi Avatar asked Oct 24 '12 19:10

Malachi


People also ask

How do I convert YYYY date to mm in Excel?

1. Select a blank cell next to your date, for instance. I1, and type this formula =TEXT(G1, "yyyy-mm-dd"), and press Enter key, then drag AutoFill handle over the cells needed this formula. Now all dates are converted to texts and shown as yyyy-mm-dd format.

How do you reverse the date in Excel?

If the original date formatting is m/d/yyyy, please enter d/m/yyyy into the Type box, and if the original date formatting is d/m/yyyy, please enter m/d/yyyy into the Type box, and finally click the OK button. See screenshot: Now the day and month are swapped in selected date cells.

How do you convert date format from Yyyymmdd to yyyy mm dd in SQL?

Convert Char 'yyyymmdd' back to Date data types in SQL Server. Now, convert the Character format 'yyyymmdd' to a Date and DateTime data type using CAST and CONVERT. --A. Cast and Convert datatype DATE: SELECT [CharDate], CAST([CharDate] AS DATE) as 'Date-CAST', CONVERT(DATE,[CharDate]) as 'Date-CONVERT' FROM [dbo].


2 Answers

You can convert the value to a date using a formula like this, next to the cell:

=DATE(LEFT(A1,4),MID(A1,5,2),RIGHT(A1,2)) 

Where A1 is the field you need to convert.

Alternatively, you could use this code in VBA:

Sub ConvertYYYYMMDDToDate()    Dim c As Range    For Each c In Selection.Cells        c.Value = DateSerial(Left(c.Value, 4), Mid(c.Value, 5, 2), Right(c.Value, 2))        'Following line added only to enforce the format.        c.NumberFormat = "mm/dd/yyyy"    Next End Sub 

Just highlight any cells you want fixed and run the code.

Note as RJohnson mentioned in the comments, this code will error if one of your selected cells is empty. You can add a condition on c.value to skip the update if it is blank.

like image 97
Daniel Avatar answered Sep 22 '22 11:09

Daniel


Do you have ROWS of data (horizontal) as you stated or COLUMNS (vertical)?

If it's the latter you can use "Text to columns" functionality to convert a whole column "in situ" - to do that:

Select column > Data > Text to columns > Next > Next > Choose "Date" under "column data format" and "YMD" from dropdown > Finish

....otherwise you can convert with a formula by using

=TEXT(A1,"0000-00-00")+0

and format in required date format

like image 22
barry houdini Avatar answered Sep 20 '22 11:09

barry houdini