5 Replies Latest reply on Jan 31, 2012 12:32 PM by techt

    Best method for two digit month


      I've done some digging, and other than use what I've been using, I'm wondering if anyone has a better way to pad a single digit month to two digits. The same hold true for dates as well. What I've been using is to have the calculation occur on the fly as short date value is needed. Below is the month, which would be in a longer string to include year, date, as well as any other formatting the client may require.


      Right ( "0" & Month ( Get ( CurrentDate ) ) ; 2 )


      It's quick, easy, and works, but I'm wondering if there isn't something I'm missing ( FMI has made tons of changes over the past 20 years ) that would make this easier.



        • 1. Re: Best method for two digit month

          Have a look at the SerialIncrement() function. There may be other ways, depending on what is the full format you are after.

          • 2. Re: Best method for two digit month
            Stephen Huston

            Hi Tim,


            Your calc is pretty simple. I would suggest that you turn this into a Custom Function (CF) so it can be used without even having to built it each time its needed:


            CF Name: MonthTwoDigits

            CF Parameter: DateToUse

            Calc: Right ( "0" & Month ( DateToUse ) ; 2 )


            It would appear as a Custom Function in the list: MonthTwoDigits (DateToUse)


            You could do this with Month, Day, and Year (4 digits pad). You could also build a full CF of DatePadded (DateToUse) which uses padding for all date parts.


            I rely on CFs for this type of cleanup all the time. Having a CF at hand that can append today's date to a time-stamped file name is really useful as well with scripted exports or Safe As outputs.


            Stephen Huston

            • 3. Re: Best method for two digit month

              Stephen, thanks for the CF suggestion. I do this quite a bit and you're right that a CF makes more sense.


              Have a great day!



              • 4. Re: Best method for two digit month



                Why not have it return the entire date formatted as you wish? Not just the day or month. If you are going for a custom function this will keep the whole calculation in one place.






                This feels weird sending an email to Tim from you guessed it Tim. LOL


                Btw good name.

                • 5. Re: Best method for two digit month

                  Agreed, that's where I'm heading. Just seemed easier to reduce it a manageable post then extrapolate. Thanks Tim!


                  Yep, that's a little weird.