Extract Number From Different Format (Date Vs General)

muhammad susanto

Well-known Member
Joined
Jan 8, 2013
Messages
2,077
Office Version
  1. 365
  2. 2021
Platform
  1. Windows
hi guys...

how to extract this number which 2 condition (date format and general format)

[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]data sample[/TD]
[TD]desired result[/TD]
[/TR]
[TR]
[TD]08/12/2005 (date format)[/TD]
[TD]2005[/TD]
[/TR]
[TR]
[TD]01/07/1992 (date format)[/TD]
[TD]1992[/TD]
[/TR]
[TR]
[TD]2001-10-380 (general format)[/TD]
[TD]2001[/TD]
[/TR]
[TR]
[TD]1986-7-451254 ((general format)[/TD]
[TD]1986[/TD]
[/TR]
</tbody>[/TABLE]

hope, someone could help me...

m.susanto
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
try =(sample column) and format as YYYY

and see what is left over, not sure the best way to extract what is basically =LEFT(sample column,4)
 
Upvote 0
If they are dates, as mole999 said:
=TEXT(A1,"yyyy")
or
=YEAR(A1)

If string with year in first 4 characters:
=LEFT(A1,4)

or for either:
=IF(CELL("type", A1)="l",LEFT(A1,4),YEAR(A1))
 
Last edited:
Upvote 0
hi guys, thank for all, it works

i have a new challenge for you to reverse order :

08/12/2005 (date format)----2005-12-08 (as text format)
01/07/1992 (date format)---1992-07-01 (as text format)
1986-7-45 (as text) ----1986-7-45 (as text- not change)
2001-10-380 (as text)---2001-10-380 (as text- not change)
 
Upvote 0
hi guys, thank for all, it works

i have a new challenge for you to reverse order :

08/12/2005 (date format)----2005-12-08 (as text format)
01/07/1992 (date format)---1992-07-01 (as text format)
1986-7-45 (as text) ----1986-7-45 (as text- not change)
2001-10-380 (as text)---2001-10-380 (as text- not change)
Give this formula a try...

=IF(COUNTIF(A1,"*-*"),A1,TEXT(A1,"yyyy-mm-dd"))
 
Upvote 0

Forum statistics

Threads
1,223,268
Messages
6,171,100
Members
452,379
Latest member
IainTru

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