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
![]() |
Patch reliability is unclear. Unless you have an immediate, pressing need to install a specific patch, don't do it. |
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, 1 month 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 Lounger -
krweaver
AskWoody Lounger -
zeddy
AskWoody_MVP
-
-
krweaver
AskWoody Lounger -
RetiredGeek
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_MVP -
RetiredGeek
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_MVP -
cmptrgy
AskWoody Lounger
Viewing 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
-
Meet Gemini in Chrome
by
Alex5723
29 minutes ago -
DuckDuckGo’s Duck.ai added GPT-4o mini
by
Alex5723
38 minutes ago -
Trump signs Take It Down Act
by
Alex5723
8 hours, 37 minutes ago -
Do you have a maintenance window?
by
Susan Bradley
50 minutes ago -
Freshly discovered bug in OpenPGP.js undermines whole point of encrypted comms
by
Nibbled To Death By Ducks
10 hours, 10 minutes ago -
Cox Communications and Charter Communications to merge
by
not so anon
11 hours, 56 minutes ago -
Help with WD usb driver on Windows 11
by
Tex265
17 hours, 6 minutes ago -
hibernate activation
by
e_belmont
20 hours, 51 minutes ago -
Red Hat Enterprise Linux 10 with AI assistant
by
Alex5723
1 day ago -
Windows 11 Insider Preview build 26200.5603 released to DEV
by
joep517
1 day, 3 hours ago -
Windows 11 Insider Preview build 26120.4151 (24H2) released to BETA
by
joep517
1 day, 3 hours ago -
Fixing Windows 24H2 failed KB5058411 install
by
Alex5723
1 hour, 51 minutes ago -
Out of band for Windows 10
by
Susan Bradley
1 day, 8 hours ago -
Giving UniGetUi a test run.
by
RetiredGeek
1 day, 15 hours ago -
Windows 11 Insider Preview Build 26100.4188 (24H2) released to Release Preview
by
joep517
1 day, 23 hours ago -
Microsoft is now putting quantum encryption in Windows builds
by
Alex5723
9 hours, 6 minutes ago -
Auto Time Zone Adjustment
by
wadeer
2 days, 3 hours ago -
To download Win 11 Pro 23H2 ISO.
by
Eddieloh
2 days, 1 hour ago -
Manage your browsing experience with Edge
by
Mary Branscombe
41 minutes ago -
Fewer vulnerabilities, larger updates
by
Susan Bradley
18 hours, 13 minutes ago -
Hobbies — There’s free software for that!
by
Deanna McElveen
1 day ago -
Apps included with macOS
by
Will Fastie
22 hours, 29 minutes ago -
Xfinity home internet
by
MrJimPhelps
19 hours, 17 minutes ago -
Convert PowerPoint presentation to Impress
by
RetiredGeek
1 day, 20 hours ago -
Debian 12.11 released
by
Alex5723
3 days ago -
Microsoft: Troubleshoot problems updating Windows
by
Alex5723
3 days, 4 hours ago -
Woman Files for Divorce After ChatGPT “Reads” Husband’s Coffee Cup
by
Alex5723
2 days, 7 hours ago -
Moving fwd, Win 11 Pro,, which is best? Lenovo refurb
by
Deo
4 minutes ago -
DBOS Advanced Network Analysis
by
Kathy Stevens
3 days, 21 hours ago -
Microsoft Edge Launching Automatically?
by
healeyinpa
3 days, 11 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.