2 Replies Latest reply on Oct 4, 2015 6:15 AM by erolst

    Need date format with hyphens...

    GeoffreyMartin

      Hey all,

       

      I want to set up a button to insert yesterdays date into a field.  The kicker is that it has to be entered into the field with hyphens, not the filemaker "/".  It's used in a URL and needs to be formatted as MM-DD-YYY.  Is there an easy way to do this?

       

      Month (Get(CurrentDate) - Day(1)) & "-" & Day(Get(CurrentDate) - Day(1)) & "-" & Year(Get(CurrentDate) - Day(1))

       

      This returns the correct format, but less one month, one day and one year.  Is text formatting the way to go (left, middle, right)?  The only issue there is that the leading 0 needs to be on the month if it's not October-December.

        • 1. Re: Need date format with hyphens...
          GeoffreyMartin

          Okay, so this worked.  Much cleaner but can't get the leading zeros on days and months

           

          Substitute (Get(CurrentDate) - Day (1) ; "/" ; "-" )

          • 2. Re: Need date format with hyphens...
            erolst

            GeoffreyMartin wrote:

            I want to set up a button to insert yesterdays date into a field.  The kicker is that it has to be entered into the field with hyphens, not the filemaker "/".  It's used in a URL and needs to be formatted as MM-DD-YYY.

             

            Why put this value into any field? You can query that value and put it into the desired format while constructing that URL.

             

            A correct way to get that format would be:

             

            Let ( [

              theDate = Get ( CurrentDate ) - 1 ; // base unit for dates is one (1) day

              m = Right ( "00" & Month ( theDate ) ; 2 ) ;

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

              ] ;

              m & "-" & d & "-" & Year ( theDate )

            )