I have a file with 2000 entries for demographics. Unfortunately the date of birth column shows dates as yyyymmdd instead of mmddyyyy And to make things worse excel is recognizing entries as “general” and not dates, so when I try to use a date formula I get ####### in the field
Is there a simple date formula to change this or do I have to parse things and then combine columns. This has to work on a 2000 plus rows for the spreadsheet
Any help appreciated
Thanks
JRK
example 19470302 should read march 2 1947 or 03/02/1947
![]() |
There are isolated problems with current patches, but they are well-known and documented on this site. |
SIGN IN | Not a member? | REGISTER | PLUS MEMBERSHIP |
-
Re arrange Date in Column from yyyymmdd to mmddyyyy
Home » Forums » AskWoody support » Productivity software by function » MS Excel and spreadsheet help » Re arrange Date in Column from yyyymmdd to mmddyyyy
- This topic has 32 replies, 6 voices, and was last updated 10 years, 2 months ago.
AuthorTopicWSjrklein
AskWoody LoungerMarch 27, 2015 at 8:19 am #499227Viewing 16 reply threadsAuthorReplies-
zeddy
AskWoody_MVPMarch 27, 2015 at 9:18 am #1497487Hi
..you could use code like this:
Code:Sub convertDates() Application.ScreenUpdating = False For Each cell In [d2:d2001] '<< adjust range required zYear = Left(cell, 4) zMonth = Mid(cell, 5, 2) zDay = Right(cell, 2) zDate = DateSerial(zYear, zMonth, zDay) cell.Value = zDate cell.NumberFormat = "dd-mmm-yyyy" '<< adjust to suit Next End Sub
..see attached example file, with 2000 datevalues
zeddy
-
krweaver
AskWoody Lounger -
WSjrklein
AskWoody LoungerMarch 27, 2015 at 10:32 am #1497497Dear Zeddy and Kweaver both of your solutions are phenomenal. Thankyou. I ran both and because some cells within the 5000 Date of birth records have 0 for a number because the date of birth had not been recorded both solutions error out. Is there a way to build in error handling for records that have 0 or are blank in their cells. I would manually enter but it seems that there are approx. 100 records throughout the spreadsheet….
Thank
Jrk
-
RetiredGeek
AskWoody_MVPMarch 27, 2015 at 10:55 am #1497506JR,
Here’s how to fix both:
Code:Sub convertDates() Application.ScreenUpdating = False For Each cell In [d2:d2001] '<< adjust range required If cell.Value "" And cell.Value 0 Then zYear = Left(cell, 4) zMonth = Mid(cell, 5, 2) zDay = Right(cell, 2) zDate = DateSerial(zYear, zMonth, zDay) cell.Value = zDate cell.NumberFormat = "dd-mmm-yyyy" '<< adjust to suit End If Next End Sub
Formula: [noparse]=IFERROR(DATE(LEFT(D2,4),MID(D2,5,2),RIGHT(D2,2)),"")[/noparse]
HTH :cheers:
RetiredGeek
AskWoody_MVPMarch 27, 2015 at 11:46 am #1497513JR,
Seems to work for me am I missing something?
39996-dateconv
HTH :cheers:-
zeddy
AskWoody_MVPMarch 27, 2015 at 1:21 pm #1497530Hi
try this..
Code:Sub convertDates() Application.ScreenUpdating = False For Each cell In [d2:d2001] '<< adjust range required If cell Like "########" Then zYear = Left(cell, 4) zMonth = Mid(cell, 5, 2) zDay = Right(cell, 2) zDate = DateSerial(zYear, zMonth, zDay) cell.Value = zDate cell.NumberFormat = "dd-mmm-yyyy" '<< adjust to suit End If Next End Sub
This makes sure that only cells that have 8 digits are processed.
see also attached..
zeddy
RetiredGeek
AskWoody_MVPMarch 27, 2015 at 1:45 pm #1497537Zeddy,
Cool! :cheers:
-
WSjrklein
AskWoody Lounger -
zeddy
AskWoody_MVP -
zeddy
AskWoody_MVP -
WSjrklein
AskWoody Lounger -
cmptrgy
AskWoody LoungerMarch 28, 2015 at 11:03 am #1497690I use dates prior to 1900 because of my genealogy album I’m building
I’m certainly no expert like these other fellows are but this is what works for meHow to calculate ages before 1/1/1900 in Excel http://support.microsoft.com/kb/245104
— Check out that websiteThis is what works for me but I have lost track of how it works, but it does in my case
Start Excel. View the worksheet on which you want to use the function.
Press ALT+F11 to switch to the Visual Basic Editor.
On the Insert menu, click Module.
Type the following code in the module‘ This is the initial function. It takes in a start date and an end date.
Public Function AgeFunc(stdate As Variant, endate As Variant)‘ Dim our variables.
Dim stvar As String
Dim stmon As String
Dim stday As String
Dim styr As String
Dim endvar As String
Dim endmon As String
Dim endday As String
Dim endyr As String
Dim stmonf As Integer
Dim stdayf As Integer
Dim styrf As Integer
Dim endmonf As Integer
Dim enddayf As Integer
Dim endyrf As Integer
Dim years As Integer‘ This variable will be used to modify string length.
Dim fx As Integer
fx = 0‘ Calls custom function sfunc which runs the Search worksheet function
‘ and returns the results.
‘ Searches for the first “/” sign in the start date.
stvar = sfunc(“/”, stdate)‘ Parse the month and day from the start date.
stmon = Left(stdate, sfunc(“/”, stdate) – 1)
stday = Mid(stdate, stvar + 1, sfunc(“/”, stdate, sfunc(“/”, stdate) + 1) – stvar – 1)‘ Check the length of the day and month strings and modify the string
‘ length variable.
If Len(stday) = 1 Then fx = fx + 1
If Len(stmon) = 2 Then fx = fx + 1‘ Parse the year, using information from the string length variable.
styr = Right(stdate, Len(stdate) – (sfunc(“/”, stdate) + 1) – stvar + fx)‘ Change the text values we obtained to integers for calculation
‘ purposes.
stmonf = CInt(stmon)
stdayf = CInt(stday)
styrf = CInt(styr)‘ Check for valid date entries.
If stmonf 12 Or stdayf 31 Or styrf < 1 Then
AgeFunc = "Invalid Date"
Exit Function
End If' Reset the string length variable.
fx = 0' Parse the first "/" sign from the end date.
endvar = sfunc("/", endate)' Parse the month and day from the end date.
endmon = Left(endate, sfunc("/", endate) – 1)
endday = Mid(endate, endvar + 1, sfunc("/", endate, sfunc("/", endate) + 1) – endvar – 1)' Check the length of the day and month strings and modify the string
' length variable.
If Len(endday) = 1 Then fx = fx + 1
If Len(endmon) = 2 Then fx = fx + 1' Parse the year, using information from the string length variable.
endyr = Right(endate, Len(endate) – (sfunc("/", endate) + 1) – endvar + fx)' Change the text values we obtained to integers for calculation
' purposes.
endmonf = CInt(endmon)
enddayf = CInt(endday)
endyrf = CInt(endyr)' Check for valid date entries.
If endmonf 12 Or enddayf 31 Or endyrf endmonf Then
years = years – 1
End IfIf stmonf = endmonf And stdayf > enddayf Then
years = years – 1
End If‘ Make sure that we are not returning a negative number and, if not,
‘ return the years.
If years < 0 Then
AgeFunc = "Invalid Date"
Else
AgeFunc = years
End IfEnd Function
' This is a second function that the first will call.
' It runs the Search worksheet function with arguments passed from AgeFunc.
' It is used so that the code is easier to read.
Public Function sfunc(x As Variant, y As Variant, Optional z As Variant)
sfunc = Application.WorksheetFunction.Search(x, y, z)
End FunctionSave the file.
Type the following data
A1 01/01/1887
A2 02/02/1945In cell A3, enter the following formula
=AgeFunc(startdate,enddate)
where startdate is a cell reference to your first date (A1) and enddate is a cell reference to your second date (A2).The result should be 58
— I have to admit I do not know what this "The result should be 58" referencesHP EliteBook 8540w laptop Windows 10 Pro (x64)
-
zeddy
AskWoody_MVP
-
-
-
RetiredGeek
AskWoody_MVPMarch 27, 2015 at 2:57 pm #1497551JR,
You can fix the formula version as follows:
[noparse]=IF(INT(LEFT(N2,4))<1900,"Prior 1900",IFERROR(DATE(LEFT(N2,4),MID(N2,5,2),RIGHT(N2,2)), ""))[/noparse]
40001-dateconv
HTH :cheers:zeddy
AskWoody_MVP-
RetiredGeek
AskWoody_MVPMarch 27, 2015 at 4:18 pm #1497561So I see this forum has moved to Los Angeles?
Is it warmer than New York there?
Haven’t been to LA for a while.
zeddyZeddy,
Yes LA is warmer than NY but what do you mean by the forum moving there? :cheers:
-
zeddy
AskWoody_MVP
-
WSjrklein
AskWoody Loungerkrweaver
AskWoody Lounger-
zeddy
AskWoody_MVP
krweaver
AskWoody LoungerRetiredGeek
AskWoody_MVPMarch 27, 2015 at 5:28 pm #1497570Zeddy,
Yeah! My fingers are faster (or slower) than the grey matter! 😆 :cheers:
FYI: I fixed it.
Maudibe
AskWoody_MVPRetiredGeek
AskWoody_MVPMarch 27, 2015 at 8:50 pm #1497586Maud,
Nice work! :clapping: But for those of us who hate to type:
Code:Sub convertDates() Range("D3") = Format(Format(Range("D3"), "####-##-##"), "mm/dd/yyyy") End Sub
Also more efficient in large workbooks as it saves a reference to the cell for each occurrence.
HTH :cheers:
-
zeddy
AskWoody_MVPMarch 28, 2015 at 6:54 am #1497646Hi
Maud: top-marks for a shorter method!RG: for even less typing:
Code:[d3] = Format(Format([d3], "####-##-##"), "mm/dd/yyyy")
But, you should be aware that this will NOT actually display the specified “mm/dd/yyyy” format in the cell if you are in the UK. (It will display as UK format dd/mm/yyyy, even though you have asked for “mm/dd/yyyy”)
RG: Try this (or anyone if you are in the USA):
Code:Sub convertDates() Range("D3") = Format(Format(Range("D3"), "####-##-##"), "dd/mm/yyyy") End Sub
Did you still get your mm/dd/yyyy US format, even though you asked for dd/mm/yyyy ????
To make sure that you get the format you actually specify, you need to specifically use..
cell.NumberFormat = “mm/dd/yyyy”So my amended routine, taking account of post#11, post#13, post#24 is now:
Code:Sub convertDates() Application.ScreenUpdating = False For Each cell In [d2:d2001] '<< adjust range required If cell Like "19######" Then cell.Value = Format(cell, "####-##-##") '<< converts to date cell.NumberFormat = "mm/dd/yyyy" '<< adjust format to suit End If Next End Sub
Thanks again to both Maud and RG for their versions.
zeddy
RetiredGeek
AskWoody_MVPMarch 28, 2015 at 8:34 am #1497659Zeddy,
It looks like a YMMV situation!
40009-zeddydate
Cell D3 starting value: 19491115 (Nov 15, 1949)
:cheers:RetiredGeek
AskWoody_MVPMarch 28, 2015 at 11:57 am #1497703Zeddy,
Your Mileage May Vary! This is the disclaimer they always give in car ads when they mention the gas mileage the car is supposed to get according to our EPA (environmental protection agency).
Trying to make sure things work across international boundaries is always a pain!
HTH :cheers:
zeddy
AskWoody_MVPcmptrgy
AskWoody LoungerViewing 16 reply threads -

Plus Membership
Donations from Plus members keep this site going. You can identify the people who support AskWoody by the Plus badge on their avatars.
AskWoody Plus members not only get access to all of the contents of this site -- including Susan Bradley's frequently updated Patch Watch listing -- they also receive weekly AskWoody Plus Newsletters (formerly Windows Secrets Newsletter) and AskWoody Plus Alerts, emails when there are important breaking developments.
Get Plus!
Welcome to our unique respite from the madness.
It's easy to post questions about Windows 11, Windows 10, Win8.1, Win7, Surface, Office, or browse through our Forums. Post anonymously or register for greater privileges. Keep it civil, please: Decorous Lounge rules strictly enforced. Questions? Contact Customer Support.
Search Newsletters
Search Forums
View the Forum
Search for Topics
Recent Topics
-
Android 15 and IPV6
by
Win7and10
20 minutes ago -
KB5058405 might fail to install with recovery error 0xc0000098 in ACPI.sys
by
Susan Bradley
6 hours, 31 minutes ago -
T-Mobile’s T-Life App has a “Screen Recording Tool” Turned on
by
Alex5723
9 hours, 12 minutes ago -
Windows 11 Insider Preview Build 26100.4202 (24H2) released to Release Preview
by
joep517
3 hours, 47 minutes ago -
Windows Update orchestration platform to update all software
by
Alex5723
16 hours, 32 minutes ago -
May preview updates
by
Susan Bradley
3 hours, 55 minutes ago -
Microsoft releases KB5061977 Windows 11 24H2, Server 2025 emergency out of band
by
Alex5723
6 hours, 6 minutes ago -
Just got this pop-up page while browsing
by
Alex5723
8 hours, 43 minutes ago -
KB5058379 / KB 5061768 Failures
by
crown
5 hours, 48 minutes ago -
Windows 10 23H2 Good to Update to ?
by
jkitc
2 hours, 57 minutes ago -
At last – installation of 24H2
by
Botswana12
1 day, 8 hours ago -
MS-DEFCON 4: As good as it gets
by
Susan Bradley
3 hours, 9 minutes ago -
RyTuneX optimize Windows 10/11 tool
by
Alex5723
1 day, 20 hours ago -
Can I just update from Win11 22H2 to 23H2?
by
Dave Easley
1 day, 13 hours ago -
Limited account permission error related to Windows Update
by
gtd12345
2 days, 9 hours ago -
Another test post
by
gtd12345
2 days, 9 hours ago -
Connect to someone else computer
by
wadeer
2 days, 4 hours ago -
Limit on User names?
by
CWBillow
2 days, 7 hours ago -
Choose the right apps for traveling
by
Peter Deegan
1 day, 21 hours ago -
BitLocker rears its head
by
Susan Bradley
1 day, 5 hours ago -
Who are you? (2025 edition)
by
Will Fastie
1 day, 4 hours ago -
AskWoody at the computer museum, round two
by
Will Fastie
1 day, 23 hours ago -
A smarter, simpler Firefox address bar
by
Alex5723
2 days, 20 hours ago -
Woody
by
Scott
3 days, 5 hours ago -
24H2 has suppressed my favoured spider
by
Davidhs
1 day, 4 hours ago -
GeForce RTX 5060 in certain motherboards could experience blank screens
by
Alex5723
3 days, 19 hours ago -
MS Office 365 Home on MAC
by
MickIver
3 days, 13 hours ago -
Google’s Veo3 video generator. Before you ask: yes, everything is AI here
by
Alex5723
4 days, 9 hours ago -
Flash Drive Eject Error for Still In Use
by
J9438
1 day, 4 hours ago -
Windows 11 Insider Preview build 27863 released to Canary
by
joep517
5 days, 4 hours ago
Recent blog posts
Key Links
Want to Advertise in the free newsletter? How about a gift subscription in honor of a birthday? Send an email to sb@askwoody.com to ask how.
Mastodon profile for DefConPatch
Mastodon profile for AskWoody
Home • About • FAQ • Posts & Privacy • Forums • My Account
Register • Free Newsletter • Plus Membership • Gift Certificates • MS-DEFCON Alerts
Copyright ©2004-2025 by AskWoody Tech LLC. All Rights Reserved.