+ Reply to Thread
Results 1 to 7 of 7

Extract numbers from date to number format

  1. #1
    Forum Contributor
    Join Date
    05-09-2013
    Location
    Berlin/Sweden
    MS-Off Ver
    Excel 2010
    Posts
    124

    Extract numbers from date to number format

    I need to extract/separate numbers from a date cell - for instance:

    24-09-13

    but when I do this:

    =RIGHT(B2,2)

    I get the number 41 and 13. I presume this has something to do with date and number format. Haven't been able to fix it. Does anybody know a good trick?

    Edit:

    Because if I change the 24-09-13 to number instead of date it turns into a weird unusable sequence of numbers such as 41541.
    Last edited by Jonathan9; 11-21-2013 at 09:12 AM.

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Extract numbers from date to number format

    Hi,

    What result are you expecting?

    If your B2 cell is a proper date number, i.e. 41541 for 24th Sept 2013 then you will get the result 41.

    If your B2 cell is the text '24-09-13 then you'll get 13.

    It's nothing to do with formatting, rather what's actually in the B2 cell.

    Has Berlin been over-run?
    Last edited by Richard Buttrey; 11-21-2013 at 09:03 AM.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,714

    Re: Extract numbers from date to number format

    A date is a number counting from 01/01/1900 ... which is day 1. So you're just getting the right and left digits.

    Use the functions DAY, MONTH and YEAR to get ... well, probably speaks for itself.


    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  4. #4
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,825

    Re: Extract numbers from date to number format

    If it is a proper date then you can use YEAR() or MONTH() or DAY() to extract those parts of it that you need.

    If you are more comfortable using string functions, then you can do this:

    =RIGHT(TEXT(B2,"dd-mm-yy"),2)

    but it is just the same as doing this:

    =YEAR(B2)

    or if you only want the last two digits of the year:

    =MOD(YEAR(B2),100)

    Hope this helps.

    Pete

  5. #5
    Forum Contributor
    Join Date
    05-09-2013
    Location
    Berlin/Sweden
    MS-Off Ver
    Excel 2010
    Posts
    124

    Re: Extract numbers from date to number format

    Quote Originally Posted by Richard Buttrey View Post
    Hi,

    What result are you expecting?

    If your B2 cell is a proper date number, i.e. 41541 for 24th Sept 2013 then you will get the result 41.

    If your B2 cell is the text '24-09-13 then you'll get 13.

    It's nothing to do with formatting, rather what's actually in the B2 cell.

    Has Berlin been over-run?
    Well, I was expecting to return 13 but Excel had me fooled once again...

    Quote Originally Posted by TMShucks View Post
    A date is a number counting from 01/01/1900 ... which is day 1. So you're just getting the right and left digits.

    Use the functions DAY, MONTH and YEAR to get ... well, probably speaks for itself.


    Regards, TMS
    Yes!


    Quote Originally Posted by Pete_UK View Post
    If it is a proper date then you can use YEAR() or MONTH() or DAY() to extract those parts of it that you need.

    If you are more comfortable using string functions, then you can do this:

    =RIGHT(TEXT(B2,"dd-mm-yy"),2)

    but it is just the same as doing this:

    =YEAR(B2)

    or if you only want the last two digits of the year:

    =MOD(YEAR(B2),100)

    Hope this helps.

    Pete
    Yes, this worked like charm. Appreciate it.

  6. #6
    Valued Forum Contributor
    Join Date
    10-29-2012
    Location
    Mojokerto,Indonesia
    MS-Off Ver
    Excel 2007
    Posts
    554

    Re: Extract numbers from date to number format

    it depend on your regional setting number of your computer.
    to ensure if data at B2 date value or not use isnumber function. if you get true, it means date value if false it means not.
    so if you want to get 2 end number of year from data at B2 try this one.
    =IF(ISNUMBER(B2),RIGHT(YEAR(B2),2),RIGHT(B2,2))

  7. #7
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,714

    Re: Extract numbers from date to number format

    You're welcome.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Extract all numbers from a cell to different cols for each number
    By nurulosman in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 09-25-2012, 07:16 AM
  2. Replies: 2
    Last Post: 01-17-2010, 10:39 AM
  3. Extract Fractional Numbers as Numbers NOT Date
    By MrBill in forum Excel Formulas & Functions
    Replies: 11
    Last Post: 11-03-2005, 03:50 PM
  4. [SOLVED] Extract Fractional Numbers as Numbers NOT Date
    By MrBill in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 11-02-2005, 06:17 PM
  5. [SOLVED] extract numbers, convert to date
    By gkaspen in forum Excel General
    Replies: 8
    Last Post: 03-01-2005, 11:08 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1