Full Date of Birth YYYY-MM-DD from 6 char. String YYMMDD

AKOsman1

New Member
Joined
Nov 19, 2023
Messages
24
Office Version
  1. 2007
Platform
  1. Windows
I have a 13 Character ID No. The first 6 characters represent the Date of Birth (YYMMDD). I want to display the date as YYYY-MM-DD eg;
470527 = 1947-05-27
500113 = 1950-01-13
000630 = 2000-06-30
050114 = 2005-01-14
Please show me how to achieve this.
 
Hi Dave, Thank you for your response. Unfortunately, I would not know what to do with the VBA code that you have sent me. I am absolutely new to VBA and have no idea what to do with this code. Can you assist, Please.
 
Upvote 0

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
My apologizes, I was just trying to help.
"Hi Dave, Thank you for your response. Unfortunately, I would not know what to do with the VBA code that you have sent me. I am absolutely new to VBA and have no idea what to do with this code. Can you assist, Please."

See Peter's VBA in post #13. I assumed that you had tried this VBA!

I suggest that you change the row with .NumberFormat = "@" to to .NumberFormat = "yyyy-mm-dd"

To ensure that the results are real dates, format the dates to a different format and endure the information is correct or look at the value of the cells in the post.
Row 3 is a copy of Row showing the result With Number format General.
If you prefer the format of yyyy-mm-dd, then just change the format back to that format. You just need to look at a few.

Dates Time.xlsm
ABCDE
1DatesTextDate
2470527ab12efg1947-05-271947-05-2727-May-47
3470527ab12efg173141947-05-2717314Number Format General
4
5500113ab12efg1950-01-131950-01-1313-Jan-50
6000630ab12efg2000-06-302000-06-3030-Jun-00
7050114ab12efg2005-01-142005-01-1414-Jan-05
8
4i
Cell Formulas
RangeFormula
C2:C3,C5:C7C2=TEXT(20-(LEFT(A2,2)-45>0)&LEFT(A2,6),"0-00-00")
D2:D3,D5:D7D2=--(TEXT(20-(LEFT(A2,2)-45>0)&LEFT(A2,6),"0-00-00"))
 
Upvote 0
I think that your excel version (2007) & how it uses "Evaluate" may be the issue as suggested by @Dave Patton.
Try this code (in a standard module)

VBA Code:
Sub Extract_Date_Text_v2()
  Application.ScreenUpdating = False
  With Range("B2:B" & Range("A" & Rows.Count).End(xlUp).Row)
    .NumberFormat = "yyyy-mm-dd"
    .Formula = "=--TEXT(20-(LEFT(A2,2)-45>0)&LEFT(A2,6),""0-00-00"")"
    .Value = .Value
  End With
  Application.ScreenUpdating = True
End Sub
 
Upvote 0
Solution
Thanks Peter, the code works 100% correctly. I sincerely appreciate your help and the effort by whoever responded.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top