+ Reply to Thread
Results 1 to 16 of 16

Combine numbers and date to cell

  1. #1
    Forum Contributor
    Join Date
    04-02-2012
    Location
    Bergen, Norway
    MS-Off Ver
    MS 365 Subscription
    Posts
    323

    Combine numbers and date to cell

    Hi,

    I am making a excelform to register projects, so I would be very happy if someone could help me with a formula to create a projectnumber.

    If:
    A1 = 20
    B1 = 65
    This year = 2024

    I want cell C1 to show 20652024

    Thanks in advance

    Best regards
    Øystein

  2. #2
    Forum Expert
    Join Date
    10-19-2021
    Location
    Brazil
    MS-Off Ver
    Office 365 V2401 w/ Win10 Home 64 Bit
    Posts
    2,014

    Re: Combine numbers and date to cell

    Use this
    Formula: copy to clipboard
    Please Login or Register  to view this content.

  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,447

    Re: Combine numbers and date to cell

    Or if A1 or A2 might have a leading zero:
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    You will probably need to change the commas to semi-colons.
    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
    Join Date
    04-23-2012
    Location
    New Jersey, USA
    MS-Off Ver
    Excel 365
    Posts
    2,410

    Re: Combine numbers and date to cell

    @TMS... You can make the part of your formula a little more compact like this...
    TEXT(NOW(),"e")

  5. #5
    Forum Guru
    Join Date
    02-27-2016
    Location
    Vietnam
    MS-Off Ver
    2016
    Posts
    5,911

    Re: Combine numbers and date to cell

    Or try:

    =TEXT(A1*1000000+B1*10000+YEAR(TODAY()),"00000000")

  6. #6
    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,447

    Re: Combine numbers and date to cell

    @Rick: thank you. I did not know you could do that. Is that documented somewhere?

  7. #7
    Forum Guru
    Join Date
    04-23-2012
    Location
    New Jersey, USA
    MS-Off Ver
    Excel 365
    Posts
    2,410

    Re: Combine numbers and date to cell

    @TMS - I presume you are you referring to the "e" metacharacter that stands in for the 4-digit year... no, I do not think it is documented, but it works correctly in the US locale as well as the European locales.

  8. #8
    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,447

    Re: Combine numbers and date to cell

    @Rick: yes. It worked for me. It also worked with TODAY() but obviously NOW() wins in the brevity stakes. Thanks again.

  9. #9
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    44,053

    Re: Combine numbers and date to cell

    Surely =YEAR(NOW()) would win in the brevity stakes??? Are there any other such metacharacters? Always interesting to find out such things...
    Glenn




    None of us get paid for helping you... we do this for fun. So DON'T FORGET to say "Thank You" to all who have freely given some of their time to help YOU.

    Temporary addition of accented to illustrate ongoing problem to the TT: L? fh?ile P?draig sona dhaoibh

  10. #10
    Valued Forum Contributor
    Join Date
    02-06-2013
    Location
    Germany
    MS-Off Ver
    365
    Posts
    491

    Re: Combine numbers and date to cell

    I was also about to ask for documentation on this as I've never seen it before.

    As far as I can tell:
    b = unclear? looks like some year counter with 1957/2057 = 00, 1956/2056 = 99 etc. ¯\_(ツ)_/¯
    d = day
    e = 4-digit year
    g = unclear? (gives me an empty cell but with some character in it)
    h = hour
    m = month
    n = unclear (gives me a #VALUE! error)
    s = seconds
    y = 2-digit year
    Last edited by RaulSerg; 03-18-2024 at 03:52 PM.

  11. #11
    Forum Guru
    Join Date
    04-23-2012
    Location
    New Jersey, USA
    MS-Off Ver
    Excel 365
    Posts
    2,410

    Re: Combine numbers and date to cell

    Just to follow up on things you can do with the TEXT function that many are not aware of... assuming you have a newer version of Excel that supports dynamic arrays, you can output different formatted patterns (number and/or date) to different columns for a range of numbers or dates with just a single formula. Let's assume you have a range of dates in cells A2:A9 and you wanted the month name in one column, the day number along with the day name in the next column and the international formatted date in the next column after that. You can supply the different format patterns in an array constant and the TEXT function will apply them accordingly. For the example I proposed, this single formula would output all three columns of formatted results for the entire range...
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Last edited by Rick Rothstein; 03-18-2024 at 04:08 PM.

  12. #12
    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,447

    Re: Combine numbers and date to cell

    Just for fun, I’ve put all the solutions and advice into a workbook.

    It checks repetitions of the formatting characters. Interestingly, "b" and "bb" give one value, "bbb" and "bbbb" give a longer value. A single "a" just returns "a", and "aa" returns "aa". "aaa", "aaaa", and "aaaaa" return variations of the Day; "Mon" and "Monday". "mmmmm" (5*"m") returns the first letter of the month.

    I had the same experience with multiples of "g" and "n"; blank and #Value! respectively.

  13. #13
    Forum Expert
    Join Date
    10-19-2021
    Location
    Brazil
    MS-Off Ver
    Office 365 V2401 w/ Win10 Home 64 Bit
    Posts
    2,014

    Re: Combine numbers and date to cell

    What I liked about "e" is that for latim countries like mine the year is "aaaa" (from 'ano') instead of "yyyy", but I can use "e" for English and latim languages.

  14. #14
    Forum Guru
    Join Date
    04-23-2012
    Location
    New Jersey, USA
    MS-Off Ver
    Excel 365
    Posts
    2,410

    Re: Combine numbers and date to cell

    Yes, that is the beauty of the 'e'... I cannot help wondering why Microsoft created it and then did not document it. Strange.

  15. #15
    Valued Forum Contributor
    Join Date
    02-06-2013
    Location
    Germany
    MS-Off Ver
    365
    Posts
    491

    Re: Combine numbers and date to cell

    Some casual mentioning can be found here (last two links only in comments) but not much more on background etc. there either:
    https://stackoverflow.com/questions/...yyyy-to-a-year
    https://excel.tips.net/T003299_Speci..._Function.html
    https://www.ablebits.com/office-addi...te-text-excel/

    Random guess based on TMS experiment: "bb"/"bbb"/"bbbb" could be this: "Thailand uses the Thai solar calendar as the official calendar, in which the calendar's epochal date (Year zero) was the year in which the Buddha attained parinibbāna. This places the current year at 543 years ahead of the Gregorian calendar. The year 2024 AD is indicated as 2567 BE in Thailand." (:
    B for Buddha - how many coincidences can there be?! :Ð

  16. #16
    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,447

    Re: Combine numbers and date to cell

    @RaulSerg: I don't think that's a coincidence (regarding the "b" options) . . , 2 digit and 4 digit Thai Solar year. Who'd a thought?

    I did also consider the options for other countries and whether or not capitalisation would make a difference . . . but that felt like a couple of steps too far.

    Edit: quick check of capitalisation indicates that it must be a lower case "e". Upper case "E" returns #VALUE! Other than that, there doesn't seem to be a difference.
    Last edited by TMS; 03-19-2024 at 05:59 AM.

+ 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. Convert or split then combine numbers from cell
    By bernardazar in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 11-29-2020, 05:34 AM
  2. Replies: 5
    Last Post: 02-19-2020, 05:12 AM
  3. [SOLVED] Move and combine numbers with different font colour format to single cell
    By L plates in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-17-2015, 08:47 AM
  4. [SOLVED] Combine Text and Date in Cell
    By swade730 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 08-08-2015, 12:24 PM
  5. [SOLVED] How to combine a text cell with a date cell so that date does not convert?
    By OmegaSea in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 06-04-2015, 01:36 PM
  6. Combine all data with same date into one cell
    By drpressl in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 02-10-2015, 03:08 PM
  7. Combine 3 numbers to date
    By Hanadi in forum Excel General
    Replies: 2
    Last Post: 06-25-2012, 06:34 AM

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