3 Replies Latest reply on Sep 9, 2015 7:01 AM by JesseH

    Set single digit numbers with a leading zero in calculation

    JesseH

      Hello,

      I am saving a layout as an Excel worksheet, in my $Path calculation I want to insert a date from a Date Field on my layout. My Date field reads 2015 0909 for September 9th 2015, but in me path it inputs 9/9/2015. i tried breaking it out by getting Year, Month, Day but my result is 2015 99. How would I set single digit numbers to have a leading zero in a calculation?

       

      Any help would be aprreciated.

      Thanks

        • 1. Re: Set single digit numbers with a leading zero in calculation
          Extensitech

          Custom Function:

           

          // x_txt_fill ( text ; numCharacters ; fillCharacter )

           

          /*

          ------------------------------------------------------------------------------------------------

          Purpose: Returns the text with a fixed width, filled in with a specific character, such as a space or zeros

           

           

          Parameters:

            text = the string to be converted

            numcharacters = the desired length of the text. IF NEGATIVE, the characters will be added to the left, rather than to the right.

            fillcharacter = the character to add to lengthen the text string

           

           

          Dependencies: None

           

           

          Example:

           

           

          Notes:

          Recursive

           

           

          ------------------------------------------------------------------------------------------------

          */

           

           

          Let ( [

          x=1

          ; text = Left (  text ; Abs ( numcharacters ) )  ;

          paddedtext =

            Case (

            numCharacters > 0 ; text & fillCharacter ;

            numCharacters < 0 ; fillCharacter & text

            )

          ; missingCharacters = Abs ( numCharacters ) - Length ( text )

           

           

          ] ;

           

           

          Case (

            missingCharacters = 0

            ; text

            ; x_txt_fill ( paddedtext ; numCharacters ; fillCharacter )

          )

           

           

          )

           

          Chris Cain

          Extensitech

          • 2. Re: Set single digit numbers with a leading zero in calculation
            erolst

            The common approach is

             

            Right ( "00" & Day ( theDate ) ; 2 )

             

            though there is also this rarely mentioned function:

             

            SerialIncrement ( "00" ; Day ( theDate ) )

            • 3. Re: Set single digit numbers with a leading zero in calculation
              JesseH

              Thanks erolst. Worked like a charm.