SOLVED

Excel formula to convert single number to year with less then/greater then

%3CLINGO-SUB%20id%3D%22lingo-sub-2255522%22%20slang%3D%22en-US%22%3EExcel%20formula%20to%20convert%20single%20number%20to%20year%20with%20less%20then%2Fgreater%20then%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2255522%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20all%2C%3CBR%20%2F%3E%3CBR%20%2F%3ENot%20sure%20what%20to%20name%20this%20topic%2C%20so%20sorry%20in%20advance%20for%20whatever%20convoluted%20name%20I%20came%20up%20with.%3CBR%20%2F%3E%3CBR%20%2F%3EBasically%2C%20I%20need%20to%20take%20a%202%20digit%20(hexadecimal)%20year%2Fmonth%20combo%2C%20i.e.%3A%3CBR%20%2F%3E%3CBR%20%2F%3E81%20%3D%20January%20of%202018%3CBR%20%2F%3Eor%2C%201A%20%3D%20October%20of%202021.%3CBR%20%2F%3E%3CBR%20%2F%3EAnd%20convert%20that%20into%20the%20year.%26nbsp%3B%20So%20take%208C%20and%20have%20cell%201%20say%202018%2C%20and%20cell%202%20say%2012.%3CBR%20%2F%3E%3CBR%20%2F%3EI%20know%20%3DLEFT(B3%2C1)%20will%20get%20me%20the%20digit%20i%20want%2C%20and%20I%20know%26nbsp%3B%3DIF(B15*1%26lt%3B5%2C%22202%22%20%26amp%3B%20B15%2C%22201%22%26amp%3BB15)%20would%20work%20(Change%20the%205%20to%20whatever%20I%20need%20the%20cutoff%20year%20to%20be)%26nbsp%3B%20But%20how%20do%20I%20combine%20them%3F%3CBR%20%2F%3E%3CBR%20%2F%3ESame%20question%20for%20the%20month%2C%20I%20know%20%3DRIGHT(B3%2C1)%20would%20get%20me%20the%20month%2C%20but%20then%20how%20do%20i%20convert%20the%20hexadecimal%20months%20(A%2CB%2CC)%20into%20the%20decimal%20months%3F%26nbsp%3B%20would%20the%20HEX2DEC%20function%20work%20correctly%20in%20combination%20with%20the%20right%20command%3F%26nbsp%3B%26nbsp%3B%3CBR%20%2F%3E%3CBR%20%2F%3EI'd%20prefer%20not%20to%20have%20to%20do%20this%20over%20multiple%20cells.%26nbsp%3B%20I%20want%20it%20to%20be%203%20cells.%3CBR%20%2F%3E%3CBR%20%2F%3ECell%201%3A%20Manually%2Fautomatically%20insert%20the%20Year%2FMonth%20combo.%3CBR%20%2F%3ECell%202%3A%20Formula%20for%20Year%3CBR%20%2F%3ECell%203%3A%20Formula%20for%20Month.%3CBR%20%2F%3E%3CBR%20%2F%3EThanks%20in%20advance!%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2255522%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EFormulas%20and%20Functions%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2255602%22%20slang%3D%22en-US%22%3ERe%3A%20Excel%20formula%20to%20convert%20single%20number%20to%20year%20with%20less%20then%2Fgreater%20then%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2255602%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1017731%22%20target%3D%22_blank%22%3E%40KaiViz%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-applescript%22%3E%3CCODE%3E%3D2018%2B(HEX2DEC(LEFT(A1))%26lt%3B5)*3%0A%3DHEX2DEC(RIGHT(A1))%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2255639%22%20slang%3D%22en-US%22%3ERe%3A%20Excel%20formula%20to%20convert%20single%20number%20to%20year%20with%20less%20then%2Fgreater%20then%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2255639%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1639%22%20target%3D%22_blank%22%3E%40Detlef%20Lewin%3C%2FA%3E%26nbsp%3B%3CBR%20%2F%3E%3CBR%20%2F%3EThe%20month%20code%20works%20great%2C%20thanks!%26nbsp%3B%20But%20the%20other%20one%20just%20gives%20me%202018%20or%202021.%26nbsp%3B%20It%20actually%20needs%20to%20do%20the%20year.%26nbsp%3B%20Which%20I%20see%20I%20didn't%20explain%20fully.%3CBR%20%2F%3E%3CBR%20%2F%3ESo%201%3D2021%2C%202%3D2022%2C%203%3D2023%2C%204%3D2024%2C%205%3Dprobably%202025%2C%20but%20then%206%20%3D%202016%2C%207%3D2017.%3CBR%20%2F%3E%3CBR%20%2F%3ESo%20this%20if%20statement%20works%3A%26nbsp%3B%3DIF(B1*1%26lt%3B5%2C%22202%22%20%26amp%3B%20B1%2C%22201%22%26amp%3BB1)%3CBR%20%2F%3E%3CBR%20%2F%3EBut%20doesn't%20incorporate%20the%20LEFT%20tag%2C%20which%20is%20where%20I%20run%20into%20issues%20trying%20to%20get%20it%20to%20work.%3CBR%20%2F%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2255819%22%20slang%3D%22en-US%22%3ERe%3A%20Excel%20formula%20to%20convert%20single%20number%20to%20year%20with%20less%20then%2Fgreater%20then%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2255819%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1017731%22%20target%3D%22_blank%22%3E%40KaiViz%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESo%20it's%20not%20a%20hexadecimal%20value%20but%20a%20combination%20of%20decimal%20and%20hexadecimal%20values.%3C%2FP%3E%3CP%3EWho%20invents%20such%20c***%3F%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-applescript%22%3E%3CCODE%3E%3DIF((--LEFT(A1))%26lt%3B5%2C%22202%22%2C%22201%22)%26amp%3BLEFT(A1)%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLINGO-BODY%3E
New Contributor

Hi all,

Not sure what to name this topic, so sorry in advance for whatever convoluted name I came up with.

Basically, I need to take a 2 digit (hexadecimal) year/month combo, i.e.:

81 = January of 2018
or, 1A = October of 2021.

And convert that into the year.  So take 8C and have cell 1 say 2018, and cell 2 say 12.

I know =LEFT(B3,1) will get me the digit i want, and I know =IF(B15*1<5,"202" & B15,"201"&B15) would work (Change the 5 to whatever I need the cutoff year to be)  But how do I combine them?

Same question for the month, I know =RIGHT(B3,1) would get me the month, but then how do i convert the hexadecimal months (A,B,C) into the decimal months?  would the HEX2DEC function work correctly in combination with the right command?  

I'd prefer not to have to do this over multiple cells.  I want it to be 3 cells.

Cell 1: Manually/automatically insert the Year/Month combo.
Cell 2: Formula for Year
Cell 3: Formula for Month.

Thanks in advance!

4 Replies

@KaiViz 

=2018+(HEX2DEC(LEFT(A1))<5)*3
=HEX2DEC(RIGHT(A1))

@Detlef Lewin 

The month code works great, thanks!  But the other one just gives me 2018 or 2021.  It actually needs to do the year.  Which I see I didn't explain fully.

So 1=2021, 2=2022, 3=2023, 4=2024, 5=probably 2025, but then 6 = 2016, 7=2017.

So this if statement works: =IF(B1*1<5,"202" & B1,"201"&B1)

But doesn't incorporate the LEFT tag, which is where I run into issues trying to get it to work.


best response confirmed by KaiViz (New Contributor)
Solution

@KaiViz 

So it's not a hexadecimal value but a combination of decimal and hexadecimal values.

Who invents such c***?

=IF((--LEFT(A1))<5,"202","201")&LEFT(A1)
Yeah it's a thing. The month is hexadecimal, the year is decimal, so it's two separate things in the same line but I need to separate because...that's how life works.

In any case, that's totally awesome and works super well! Thanks very much!