4 Replies Latest reply on Feb 26, 2014 8:38 AM by beverly

    Current date formatted

    tom007

      Hi

      I forgot my skills and need to update again. Sorry the newbie question and errors:

      Want to enter current date on auto-enter field.

      The format must be:

      yyyy-mm-dd

       

      Not "/"

       

      With leading zero on 1 digit day.

       

      Like this: 2014-01-01

       

      Get error on this calculation:

       

      Let(x=Get ( CurrentDate );"")

       

      Left ( x ; 2)

       

      & "-" &

       

      Middle ( x ; 4 ; 2 ) )

       

      & "-" &

       

      Right ( x ; 4)

       

      The problem is that Get ( CurrentDate ) don't get leading zero, for example, gives this: 1/1/2014 with this format m/d/yy

       

      Thanks.

       

      Tom

        • 1. Re: Current date formatted
          erolst

          To format your date display, use the Data section of the Inspector in layout mode.

          • 2. Re: Current date formatted
            Mike_Mitchell

            Tom -

             

            Try:

             

            Let ( [

            todaysDate = Get ( CurrentDate ) ;

            todaysYear = Year ( todaysDate ) ;

            todaysMonth = Month ( todaysDate ) ;

            todaysDay = Day ( todaysDate )

            ] ;

             

            todaysYear & "-" & Right ( "0" & todaysMonth ; 2 ) & "-" & Right ( "0" & todaysDay ; 2 )

             

            )

             

            HTH

             

            Mike

             

            * Edit: erolst is correct if all you want to do is change how the date is displayed (as opposed to changing the actual data in the field).

            • 3. Re: Current date formatted
              tom007

              Thank you Mike. It works excellent. Thank you to erolst.

              • 4. Re: Current date formatted
                beverly

                tom, I like to use

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

                rather than the single "0". I do genealogy, pedigree tracking and all sorts of thing where a given Day (or even Month) is unknown. If it's a text:

                     YYYY-00-00

                then it sorts as I want it and it can be "parsed" easily enough. Yes, probably not a "valid" date to FMP, but you need that "text" for reports often.

                 

                So, even where I need valid dates, I still use the "00" just for consistency throughout all my solutions and FMP doesn't squawk!

                 

                HTH,

                Beverly