Extract date from "number"

Tom.Jones

Well-known Member
Joined
Sep 20, 2011
Messages
508
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
  2. Mobile
Hi,

This VBA code was written by Peter_SSs, in "Full Date of Birth YYYY-MM-DD from 6 char. String YYMMDD"

VBA Code:
Sub Extract_Date_Text()
  With Range("B2:B" & Range("A" & Rows.Count).End(xlUp).Row)
    .NumberFormat = "@"
    .Value = Evaluate(Replace("TEXT(20-(LEFT(#,2)-45>0)&LEFT(#,6),""0-00-00"")", "#", .Offset(, -1).Address))
  End With
End Sub

@Peter_SSs
please modify the VBA code to extract data (something like AKOsman1 post) with difference that numbers in column A (starting in A2)
are like this:
1 or 2 in front of say 470207 mean year is from 1900 to 1999
3 or 4 front of say 470207 mean year is from 1800 to 1899
5 or 6 in front of say 050207 mean year is from 2000 to 2999

In column A numbers is like:
1470207 in column B will be 1947-02-07 or if is possible 07.02.1947 (european date)
5050207 in column B will be 2005-02-07 or if is possible 07.02.2005

Thank you.
 
Last edited:

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Hi,

This VBA code was written by Peter_SSs, in "Full Date of Birth YYYY-MM-DD from 6 char. String YYMMDD"

VBA Code:
Sub Extract_Date_Text()
  With Range("B2:B" & Range("A" & Rows.Count).End(xlUp).Row)
    .NumberFormat = "@"
    .Value = Evaluate(Replace("TEXT(20-(LEFT(#,2)-45>0)&LEFT(#,6),""0-00-00"")", "#", .Offset(, -1).Address))
  End With
End Sub

@Peter_SSs
please modify the VBA code to extract data (something like AKOsman1 post) with difference that numbers in column A (starting in A2)
are like this:
1 or 2 in front of say 470207 mean year is from 1900 to 1999
3 or 4 front of say 470207 mean year is from 1800 to 1899
5 or 6 in front of say 050207 mean year is from 2000 to 2999

In column A numbers is like:
1470207 in column B will be 1947-02-07 or if is possible 07.02.1947 (european date)
5050207 in column B will be 2005-02-07 or if is possible 07.02.2005

Thank you.
Excel doesn't support dates before the year 1900. It would have to return those values as a text string and not an actual date value.
 
Upvote 0
Excel doesn't support dates before the year 1900. It would have to return those values as a text string and not an actual date value.

It is not a problem.
 
Upvote 0
Try
VBA Code:
Sub Extract_Date_Text()
  With Range("B2:B" & Range("A" & Rows.Count).End(xlUp).Row)
    .Value = Evaluate(Replace("right(#,2)&"".""&mid(#,4,2)&"".""&lookup(--left(#,1),{1,3,5},{19,18,20})&mid(#,2,2)", "#", .Offset(, -1).Address))
  End With
End Sub

Sample In/Out

Tom.Jones.xlsm
AB
1InOut
2147020707.02.1947
3505020707.02.2005
4405122727.12.1805
Sheet2
 
Upvote 0
Solution

Forum statistics

Threads
1,215,069
Messages
6,122,958
Members
449,096
Latest member
Anshu121

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