Home > front end >  Get number before delimiter and -1 (previous month)
Get number before delimiter and -1 (previous month)

Time:10-29

I use this function: =IF(((LEFT(A2,FIND("-",A2)-1))-1)<10,"0"&(LEFT(A2,FIND("-",A2)-1))-1,IF((LEFT(A2,FIND("-",A2)-1)-1)<=1,LEFT(A2,FIND("-",A2)-1) 11,LEFT(A2,FIND("-",A2)-1)-1))

Which returns the good value when the number is less than "10": https://i.stack.imgur.com/ZgOuO.png

But when the number is "1" the function should return "12" but it returns 00...: https://i.stack.imgur.com/Q1tTj.png

Basically, I want to subtract a month to each number. ie: 09 = 08 OR 12 = 11 etc But when it goes to 01 (January) I need to return 12 (for December). Any idea how to perform that or fix my function, please?

CodePudding user response:

Try something along these lines:

=TEXT(EOMONTH(--LEFT(A1,7),-1),"mm")

Or, avoid the TEXT() function and just use a custom number format like mm.

  • Related